- Yii 1.1 Application Development Cookbook
- Alexander Makarov
- 186字
- 2021-04-02 18:41:02
Using controller context in a view
Yii views are pretty powerful and have many features. One of them is that you can use controller context in a view. So, let's try it.
Getting ready
Set up a new application using yiic webapp
.
How to do it...
- Create a controller as follows:
class WebsiteController extends CController { function actionIndex() { $this->pageTitle = 'Controller context test'; $this->render('index'); } function hello() { if(!empty($_GET['name'])) echo 'Hello, '.$_GET['name'].'!'; } }
- Now, we will create a view showing what we can do:
<h1><?php echo $this->pageTitle?></h1> <p>Hello call. <?php $this->hello()?></p> <?php $this->widget('zii.widgets.CMenu',array( 'items'=>array( array('label'=>'Home', 'url'=>array('index')), array('label'=>'Yiiframework home', 'url'=>'http://yiiframework.ru/', ), ))?>
How it works...
We are using $this
in a view to refer to a currently running controller. When doing it, we can call a controller method and access its properties. The most useful property is pageTitle
which refers to the current page title and there are many built-in methods that are extremely useful in views such as renderPartials
and widget
.
There's more…
The following URL contains API documentation for CController
where you can get a good list of methods you can use in your view:
推薦閱讀
- Word-Excel-PowerPoint 2010三合一從新手到高手(超值版)
- Hi!扁平化Photoshop扁平化用戶界面設計教程
- 中文版CorelDRAW X7基礎培訓教程(移動學習版)
- OpenStack實戰指南
- 圖像處理基礎教程(Photoshop CS5)(第2版)
- Learning Facebook Application Development
- PPT 2016幻燈片設計與制作從入門到精通
- 中文版Photoshop CS6經典自學教程
- PPT設計與制作實戰教程
- 攝影師的后期必修課(調色篇)
- 計算機輔助翻譯基礎與實訓
- Flash CC動畫制作與應用(第3版)
- 中文版SolidWorks 2018完全實戰技術手冊
- 攝影師的后期必修課(RAW格式篇)
- Mobile Web Development