duanqiao2006 2013-06-07 15:53
浏览 13
已采纳

如何制作可在许多视图中使用的变量?

I have a project, it has a structure like this:

http://img526.imageshack.us/img526/2333/92348689.png

I want to make a variable like the following

$templatePath = $this->baseUrl('/application/templates/')` 

and it can be used in many views, in many modules. I think I can do it by declaring the variable in Bootstrap.php (application) but I don't know how to do that.

  • 写回答

3条回答 默认 最新

  • douyingzhan5905 2013-06-08 21:29
    关注

    Usually, I just place myself such variables into application bootstrap file. Here's an example:

    class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
    
        protected function _initViewVariables() {
            $this->bootstrap('View');
    
            $this->view->fooValue = 'foo';
            $this->view->barValue = 'bar';
    
            $config = Zend_Registry::get('config');
    
            if( $config->recaptcha->enabled ) {
                $this->view->captcha = true;
                $this->view->recaptchaPublicKey = $config->recaptcha->publicKey;
            }
            else {
                $this->view->captcha = false;
            }
    
        }
    
    }
    

    I hope it helps!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?