1.Layout概念:
先看一下基本的页面结构:
如上图,在MixMVC3.1中有一个布局(Layout 一些框架称之为container)的概念,它表示页面的基本容器。
一般我们把head 元素,html body页面基础元素放到layout之中。还可以把一些基本的固定页面结构如上图黑色部分,放到layout之中。
2.Layout的编写:
Layout文件一般存放在application/views/__layouts 目录下
通过controller中的$layout 变量定义流程中使用的layout文件。
一个常见的layout如下:
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title><?php echo $this->systemName, ' > ', $this->pageTitle ?></title> <?php $this->stylesheet('admin.css'); $this->script(array('mootools/core-1.2.5.js', 'mootools/more-1.2.4.2.js', 'application.js')); ?> </head> <body> <div class="head"> <h1 class="sys-name sm-sys-name"><?php echo $this->systemName; ?></h1> <div class="w960 l-center"> <?php $this->widget('admin/top_nav'); ?> </div> </div> <div class="body"> <div class="w960 l-center"> <div class="main" id="main_content"> <?php $this->content(); ?> </div> <div class="c"></div> </div> </div> <div class="foot"></div> </body> </html>
如上代码片段中,所有view文件中都可以使用$this->stylesheet方法输出css定义,
$this->script方法输出javascript定义。其他如$this->××××的定义在controller中,可以查看具体action中的代码。Layout经常(非一定)会出现是的<?php $this->content(); ?>是用来输出具体view的内容。
3.Widget概念:
widget相当于UI编程中的组件。它可以是一个侧边栏,也可以是一个登录框或者轮换banner。Widget可以广泛用于整个页面布局中,可以使用在layout之中,也可以用的view content中。
4.Widget的编写:
Widget一般存放在application/views/__widget目录中,框架预定义了一个有用的widget用户生成列表及表单,这个之后会有另外一个文章详细说明基础widget的用法。在view中调用一个widget的方法是$this->widget(‘admin/top_nav'[, params]); 第一个参数是widget文件的路径,第二个参数是需要传到具体的widget的参数。
一个简单的widget调用
<?php $this->widget('admin/top_nav', array( 'widgte_name' => 'Hello World!', ));
admin/top_nav.phtml
<ul class="top-nav"> <li><?php echo $widgte_name ?> </li> </ul>
top_nav widget中的$widgte_name就是调用的时候传进去的。
发表评论
要发表评论,您必须先登录。