Zend layout

配置:

在application.ini中添加:

resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts" 代表去哪找layout模板

resources.layout.layout = "layout" 代表用哪个layout

具体目录如下:

  1. application
  2. |-- Bootstrap.php
  3. |-- configs
  4. |   `-- application.ini
  5. |-- controllers
  6. |-- layouts
  7. |   `-- scripts
  8. |       |-- layout.phtml

访问布局对象

有三种方法可以做:

  • 在视图页面中,使用layout()视图助手,将会返回用前端控制其注册的Zend_Layout

    1. <?php  $layout =  $this-> layout ( )?>

    由于返回了Zend_Layout实例, 你就可以直接调用它的方法,而不是给它赋变量。

    在控制器中,使用layout()控制器助手,就像视图助手一样

    1. // Calling helper as a method of the helper broker:
    2. $layout =  $this->_helper-> layout ( );
    3.  
    4. // Or, more verbosely:
    5. $helper =  $this->_helper-> getHelper ( 'Layout' );
    6. $layout =  $helper-> getLayoutInstance ( );

    调用静态方法getMvcInstance(),返回由bootstrap resource注册的layout实例

    1. $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 

    设置变量

    1. // Setting content:
    2. $layout-> somekey =  "foo"
    3.  
    4. // Echoing that same content:
    5. echo  $layout-> somekey// 'foo'
    6.  
    7. // Using the assign() method:
    8. $layout-> assign ( 'someotherkey''bar' );
    9.  
    10. // Access to assign()'d variables remains the same:
    11. echo  $layout-> someotherkey// 'bar'

    禁用layout:

    1. $layout-> disableLayout ( );


    设置其他layout

  1. // Use the layout script "alternate.phtml":
  2. $layout-> setLayout ( 'alternate' );



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值