通過controller的action可以對(duì)應(yīng)映射到一個(gè)視圖頁面。基本的規(guī)則如下:
1.文件擴(kuò)展名為phtml,該文件根目錄默認(rèn)是應(yīng)用的/application/views/scripts下。action的html文件對(duì)應(yīng)為controller類名稱文件夾/action名稱.phtml
例如:IndexController的indexAction對(duì)應(yīng)的phtml文件為application/views/scripts/index/index.phtml
注意名稱大小寫問題。
2.視圖文件的內(nèi)容是常規(guī)的php,html,js,css代碼。
例如errorAction的默認(rèn)視圖文件內(nèi)容如下:
/zf_demo1/application/views/scripts/error/error.phtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Zend Framework Default Application</title></head><body> <h1>An error occurred</h1> <h2><?php echo $this->message ?></h2> <?php if (isset($this->exception)): ?> <h3>Exception information:</h3> <p> <b>Message:</b> <?php echo $this->exception->getMessage() ?> </p> <h3>Stack trace:</h3> <pre><?php echo $this->exception->getTraceAsString() ?> </pre> <h3>Request Parameters:</h3> <pre><?php echo $this->escape(var_export($this->request->getParams(), true)) ?> </pre> <?php endif ?></body></html>
ZendFramework的視圖提供的功能非常強(qiáng)大,可以自定定義視圖,使用第三方(例如:smarty)作為視圖,并且提供很多常用的方法。具體的稍后講解。