drfu29983 2010-01-30 17:40
浏览 56
已采纳

Zend Framework,实现布局的最佳方式

I'm learning ZF for two weeks so far. Like it so much. I'd like to ask, what is the best practice for layouts? I got one layout and I need to include few variables for it. Do I need to do this in every controller?

The second question is about hiding one part of the layout. Currently I'm doing this as following:

if(Zend_Controller_Front::getInstance()->getRequest()->getControllerName() !== 'page') { ?>
    <div>
      This div should be displayed only on one page
    </div>
<?php } ?>

Is this a good practice? Maybe you could share your own?

Thanks in advance for any replies and comments! Cheers!

  • 写回答

1条回答 默认 最新

  • dsa4d4789789 2010-01-30 19:22
    关注

    You can set the variables for your layout in the bootstrap:

    protected function _initViewVars() {
        $this->bootstrap('view');
        $view = $this->getResource('view');
        $view->myvar = 'test';
    }
    

    You would then be able to access it with $this->myvar in the layout.

    For your 2nd question, I would set a view variable inside the controller to indicate that a section of the layout should be hidden.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?