cakephp 2 - 根据布局加载助手

时间:2013-02-08 17:04:30

标签: cakephp layout helpers cakephp-2.2

我想根据布局加载助手。 我想要这样的东西,但是id不起作用:

function beforeRender(){
  if (array_key_exists($this->request->action, $this->custom_layouts)){
    public $helpers = array('Html', 'Form', 'Session', 'Menu1');                
    $this->layout = $this->custom_layouts[$this->action];

  }else{
    public $helpers = array(
      'Session',
      'Html' => array('className' => 'TwitterBootstrap.BootstrapHtml'),
      'Form' => array('className' => 'TwitterBootstrap.BootstrapForm'),
      'Paginator' => array('className' => 'TwitterBootstrap.BootstrapPaginator'),
      'Menu1'
    );
    $this->layout = 'default';
  }
} 

感谢您的帮助 问候

1 个答案:

答案 0 :(得分:2)

你不能在方法中声明public $helpers

你需要调用它,因为PHP希望它被调用:

$this->helpers[] = 'Menu1';
$this->helpers['Html'] = array('className' => 'TwitterBootstrap.BootstrapHtml');
...