如何在Yii框架中进行自定义布局 [英] How to make custom layout in Yii framework
问题描述
我是yii的新手,请告诉我如何将html模板转换为yii框架
I am new to yii please tell me how to convert html template to yii framework
请给我一些链接以显示一些示例.
give me some links for it to show some examples.
推荐答案
我不清楚您的问题,无论如何,如果您想进行新的Yii布局,则通常需要执行以下步骤:
I didn't get your question clearly, anyway if you want to make a new Yii layout, you need to do these steps in general:
- 在protected/views/layouts目录中创建一个新的php文件,并将其命名
例如new-temp.php.此页面应打印此var
<?php echo $content; ?>
-
在同一目录中创建另一个php文件,将其命名为new-temp-widget.php,该文件应包含以下代码:
<?php $this->beginContent('//layouts/new-temp'); ?><div id="content"><?php echo $content; ?></div><?php $this->endContent(); ?>
- create a new php file in the protected/views/layouts dir, name it
new-temp.php for example. this page should print this var
<?php echo $content; ?>
create another php file in the same dir, name it new-temp-widget.php , this file should contain the following code :
<?php $this->beginContent('//layouts/new-temp'); ?><div id="content"><?php echo $content; ?></div><?php $this->endContent(); ?>
最后,要将此模板用于特定操作,只需在操作函数$this->layout = '//layouts/new-temp-widget';
中编写此代码
或者,如果您想将此模板应用于整个控制器,请在控制器内部添加var:public $layout='//layouts/new-temp-widget';
Finally, to use this template for a certain action, just write this code inside the action function $this->layout = '//layouts/new-temp-widget';
OR if you want to apply this template for the whole controller, add var inside the controller: public $layout='//layouts/new-temp-widget';
有关更多详细信息,请参见以下链接:使用Yii中的布局
for more details see this link : Working with Layouts in Yii
这篇关于如何在Yii框架中进行自定义布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!