配置:
在application.ini中添加:
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts" 代表去哪找layout模板
resources.layout.layout = "layout" 代表用哪个layout
具体目录如下:
-
application
-
|-- Bootstrap.php
-
|-- configs
-
| `-- application.ini
-
|-- controllers
-
|-- layouts
-
| `-- scripts
-
| |-- layout.phtml
访问布局对象
有三种方法可以做:
-
在视图页面中,使用layout()视图助手,将会返回用前端控制其注册的Zend_Layout
-
<?php $layout = $this-> layout ( ); ?>
由于返回了Zend_Layout实例, 你就可以直接调用它的方法,而不是给它赋变量。
在控制器中,使用layout()控制器助手,就像视图助手一样
-
// Calling helper as a method of the helper broker:
-
$layout = $this->_helper-> layout ( );
-
-
// Or, more verbosely:
-
$helper = $this->_helper-> getHelper ( 'Layout' );
-
$layout = $helper-> getLayoutInstance ( );
调用静态方法getMvcInstance(),返回由bootstrap resource注册的layout实例
-
$layout = Zend_Layout:: getMvcInstance ( );
通过bootstrap,取得layout resource,将会返回Zend_Layout实例。
Anywhere you have access to the bootstrap object, this method is preferred over using the static
设置变量
-
// Setting content:
-
$layout-> somekey = "foo"
-
-
// Echoing that same content:
-
-
// Using the assign() method:
-
$layout-> assign ( 'someotherkey', 'bar' );
-
-
// Access to assign()'d variables remains the same:
禁用layout:
-
$layout-> disableLayout ( );
-
-
// Use the layout script "alternate.phtml":
-
$layout-> setLayout ( 'alternate' );