美文网首页
Yii2.0 视图模版继承与模版相互调用

Yii2.0 视图模版继承与模版相互调用

作者: 小马儿_ | 来源:发表于2019-01-28 16:32 被阅读0次

模板继承与模板之间的相互调用

在控制器中单独定义父模板

public $layout = 'home';
    public function actionIndex()
    {
        return $this->render('index');
    }

在views文件夹下layouts文件夹写一个home.php

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Page Title</title>
</head>
<body>
    <p style="color:red;">我是父模板</p>
    <?=$content?>  //通过此方法告诉继承文件的内容放在这里
</body>
</html>

模板相互调用

<?=$this->render('test');?>

相关文章

网友评论

      本文标题:Yii2.0 视图模版继承与模版相互调用

      本文链接:https://www.haomeiwen.com/subject/tmjajqtx.html