- 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:
推薦閱讀
- ModelSim電子系統分析及仿真(第3版)
- 數據、模型與決策:基于Excel的建模和商務應用
- Spring Web Flow 2 Web Development
- 工業產品設計(Inventor 2010)
- Procreate+ SketchUp +Photoshop建筑設計手繪表現技法
- Android User Interface Development: Beginner's Guide
- Photoshop+CorelDRAW平面設計實例教程(第4版)
- MATLAB 2022a從入門到精通
- 陌上花開:古風CG插畫繪制技法精解(花卉篇)
- Premiere Pro短視頻剪輯零基礎一本通
- Autodesk Ecotect Analysis綠色建筑分析應用
- Word-Excel-PowerPoint 2010三合一辦公應用實戰從入門到精通(超值版)
- PHP and MongoDB Web Development Beginner's Guide
- 中文版UG NX 7.0基礎教程
- Mastering Redis