2017-07-26 39 views
0

我想爲yii使用3個模板。我有這樣的文件:如何在Yii2中使用自定義佈局?

./views/layouts/main-template-1.php 
./views/layouts/main-template-2.php 
./views/layouts/main-template-3.php 

我可以做些什麼來應用所有的佈局?因爲我爲我的網站使用了3個模板。在此先感謝

回答

1

只需簡單地在控制器或控制器的動作

$this->layout = 'main-template-1'; // or 2 or 3 
1

如果你想使用的佈局中控制所有操作,

class SiteController extends Controller 
{ 
    public $layout="main-template-1"; 
    // actions 
} 

如果您要使用特定的動作佈局比使用

public function actionIndex() 
{ 
$this->layout = "main-template-1"; 
} 
1

如果你有基本的模板,你想使用你可以等,在配置/ web.php像

'view' => [ 
     'theme' => [ 
      'pathMap' => [ 
        '@app/views' =>[ 
          '@app/themes/mytheme', 
          '@app/themes/yourtheme' 
          ] 
         ], 
      'baseUrl' => '@web/../themes/mytheme', 
     ], 
    ], 

這將需要的

app/themes/mytheme/layout/main.php 

則佈局中的功能,你可以使用其他模板一樣

public function actionIndex() 
{ 
    $this->layout = "main-template-1"; 
} 
相關問題