程序员人生 网站导航

Zend Framework教程-MVC-View(Zend_View)

栏目:ZendFramework时间:2013-10-19 00:40:28

通过controller的action可以对应映射到一个视图页面。基本的规则如下:

1.文件扩展名为phtml,该文件根目录默认是应用的/application/views/scripts下。action的html文件对应为controller类名称文件夹/action名称.phtml

例如:IndexController的indexAction对应的phtml文件为application/views/scripts/index/index.phtml

 注意名称大小写问题。

2.视图文件的内容是常规的php,html,js,css代码。


例如errorAction的默认视图文件内容如下:

/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的视图提供的功能非常强大,可以自定定义视图,使用第三方(例如:smarty)作为视图,并且提供很多常用的方法。具体的稍后讲解。


------分隔线----------------------------
------分隔线----------------------------

最新技术推荐