- 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:
推薦閱讀
- 突破平面Photoshop UI界面設計與制作剖析
- 自己動手寫分布式搜索引擎
- 性能測試從零開始
- 軟件定義數據中心:技術與實踐
- Solid Works 2021產品設計標準教程
- Python Text Processing with NLTK 2.0 Cookbook: LITE
- 3ds Max & Unreal Engine 4:VR三維建模技術實例教程(附VR模型)
- 圖解Word 2007圖文排版與辦公應用
- CAD/CAM技術與應用
- Procreate+ SketchUp +Photoshop建筑設計手繪表現技法
- Adobe創意大學Illustrator CS5 產品專家認證標準教材
- 新編AutoCAD制圖快捷命令速查一冊通
- 中文版Dreamweaver基礎培訓教程
- Photoshop CC摳圖+修圖+調色+合成+特效實戰視頻教程
- PowerPoint 2016實戰從入門到精通(超值版)