我們可以把Widget視為一個嵌入到控制器管理 的視圖中的微控制器,其實就是.net框架中的用戶控件,或者類似于.netMVC中的子視圖。與controller相比較,微件沒有既沒有動作,也沒有過濾器。
Yii 手冊中提到Widget擁有自己的視圖。
第一種方法 使用beginWidget 和endWidget
第二種方法 使用Widget('類名字')
如:
<?php
$this
->widget(
'HelloWidget'
); ?>
繼承 CWidget 以及重載它的init() 和 run() 方法,可以定義一個新的組件:
掛件的使用:面包屑導航:第一步 聲明屬性Onecandefinea Then, in each view script, one only needs to assign the "breadcrumbs" property as needed.于是乎,你需要時,只需要在每個視圖腳本中,指定breadcrumbs屬性(就可以顯示出網頁導航了).以上是官方提供的文檔文件的介紹.下面介紹視圖文件中寫法: $this->breadcrumbs=array( 'Users'=>array('index'), 參考 http://www.php100.com/manual/yii/CWidget.html#__construct-detail$this->widget('zii.widgets.CBreadcrumbs', array( 'links'=>$this->breadcrumbs,));
第二步 設置屬性 'Create', // 形式 : 'key' =>'value' key的位置相當于最后顯示出來的a標簽內的名字, value則相當于a標簽的href屬性. // 'Create'表示當前頁 故沒有設置鏈接.);其他掛件
新聞熱點
疑難解答