2013-02-08 2 views
0

레이아웃에 따라 도우미를로드하고 싶습니다. 내가 이런 식으로 뭔가를 원하지만 아이디 doesnt't 작업 : 어떤 도움cakephp 2 - 레이아웃에 따라 도우미로드하기

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'; 
    } 
} 

감사 관련

답변

2

당신이 JUSE public $helpers 내부 메소드를 선언 캔트. 동적으로 'BootstrapHtmlHelper'에 매핑 (예 : 때때로 $ this-> html로 같은 별칭으로 다른 헬퍼를 사용하는 경우

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

테스트하십시오 때로는 :

당신은 PHP가 호출되고 싶어로 호출 할 필요가 'HtmlHelper')는 예상대로 작동합니다. 동일한 별칭을 다른 클래스에 할당하면 Cake 캐시에 문제가 발생할 수 있으며 예기치 않은 결과가 발생할 수 있습니다 (예 : '잘못된'객체 유형을 무작위로 첨부). 적어도 이것은 '모델'의 경우입니다. 그러나 다른 클래스에도 동일하게 적용될 수 있습니다. – thaJeztah

+0

대단히 감사드립니다. 완벽하게 작동합니다. 지금까지는 예상대로 – mart

+0

@martin이 좋은 결과를 얻었지만 디버그를 0으로 설정하여 테스트했는지 확인하십시오. 단지 캐싱 만 사용 가능하기 때문입니다. – thaJeztah