2012-10-14 4 views
2

내 웹 프로젝트에서 Yii 프레임 워크를 사용하고 있습니다. 이제 여러 개의 모듈이 있고 모든 모듈에 대해 하나의 레이아웃 만 사용하고 싶습니다. 각 모듈의 초기화() 함수가 동일한 코드를 사용하여 수행하는 다른 용액Yii의 여러 모듈에 공통 레이아웃 사용

$this->layoutPath = Yii::getPathOfAlias('application.views.layouts'); 
$this->layout = '//layouts/myLayout'; 

있는가 : I는 각 모듈의 각 제어기/동작의 레이아웃을 결정하기 위해 다음과 같은 코드를 사용했다? 다른 말로하면, 위의 2 줄 코드를 각 동작에 작성해야하며 좋지 않아서 코드 줄 수를 줄이려고합니다.

class StaffModule extends CWebModule 
{ 
    public $layout; 
    public $layoutPath; 
    public function init() 
    { 
     $this->layoutPath = Yii::getPathOfAlias('application.views.layouts'); 
       $this->layout = '//layouts/myLayout'; 
     $this->setImport(array(
      'staff.models.*', 
      'staff.components.*', 
     )); 
    } 
} 

그러나 작동하지 않습니다. 도와주세요, 제발.

답변

0

권리 direction..I이 문제가 될 수 있다고 생각 당신이 //layouts..

$this->layoutPath = Yii::getPathOfAlias('application.views.layouts'); 
$this->layout = 'myLayout'; 

이 안되며, 그렇지 당신이 layoutPath을 정의하는대로 초기화 기능에서 발생하는 접근 방식은 ...입니다 이 필요합니다

public $layout; 
public $layoutPath; 
0

나는

using common layout for several modules

0123에 비슷한 질문에 대답했습니다

솔루션은 모듈의 beforeControllerAction에 대한 레이아웃을 설정합니다. 작동해야합니다.

2

그냥

$ this-> 레이아웃 = '// 레이아웃/myLayout'를 사용;

없이

$ this-> layoutPath = YII :: getPathOfAlias ​​('application.views.layouts');

왜냐하면 // 루트에서 특정 절대 경로를 의미합니다.