天天看點

YII view 常用extensions

帶menu的面包屑exbreadcrumbs支援自定義css。http://www.yiiframework.com/extension/exbreadcrumbs

cgridview總計插件 http://www.yiiframework.com/extension/gridcolumns/

多檔案上傳

YII view 常用extensions

<?php echo $form->textfield($model,'file[]',array('id'=>'file'));?>  

<?php echo chtml::activefilefield($model,'xian[]',array('id'=>'xiangguan'));?>  

textarea

YII view 常用extensions

<?php echo $form->textarea($model,'describe',array('cols'=>40,'rows'=>4)); ?>  

checkbox

YII view 常用extensions

<?php echo $form->checkboxlist($model,'fid',array('1'=>'中國', '2'=>'日本')); ?>  

<?php echo chtml::checkbox('id[]',''); ?>  

<?php echo $form->checkbox($model,'province', array('value'=>'上海市','uncheckvalue'=>'')); ?>  

斜杠是從views目錄開始寫的

YII view 常用extensions

$this->render( "/site/flash_message"); //完整路徑 view/site/flash_message.php   

當 使用 render()時,布局被隐式應用.視圖腳本 protected/views/layouts/main.php是預設的布局檔案 .

YII view 常用extensions

public $layout='//layouts/column2';  

進行自定義。要渲染一個不帶布局的視圖,則需調用 renderpartial() 。

在view中調用layout

YII view 常用extensions

<?php $this->begincontent('application.views.layouts.main'); ?>  

html between  

<?php $this->endcontent(); ?>   

下拉框  預設選中

YII view 常用extensions

<?php echo chtml::dropdownlist('category', '',chtml::listdata($cat, 'id', 'category')); ?>  

<?php echo $form->dropdownlist($model, 'type', array(1=>'user', 2=>'admin'),array('prompt' =>'請選擇','class'=>'a'), array('options'=>array('1'=>array('selected'=>true)))); ?>  

form表單标簽

YII view 常用extensions

<?php echo chtml::beginform(yii::app()->createurl($this->route));?>  

<?php echo chtml::endform(); ?>  

<?php $form=$this->beginwidget('cactiveform', array(  

    'action'=>'index.php?r=site/update',  

    'enableajaxvalidation'=>false,  

)); ?>  

<?php $this->endwidget(); ?>  

普通form注意加hidden r否則get得不到r=controllerid/actionid

YII view 常用extensions

<form name="product" action="<?php echo yii::app()->createurl($this->route);?>" method="get">  

<input type="hidden" name="r" value="controllerid/actionid"/>   

submit按鈕

YII view 常用extensions

<?php echo chtml::submitbutton($model->isnewrecord ? 'create' : 'save'); ?>  

radios  //給預設值

YII view 常用extensions

<?php echo $form->radiobutton($model,'province', array('value'=>'上海市','uncheckvalue'=>'')); ?>  

<?php echo chtml::radiobuttonlist('level', null, $levels); ?>  

<?php $model->gift=1;echo $form->radiobuttonlist($model,'gift',array('1'=>'是','0'=>'否'),array('separator'=>'')); ?>  

連結

YII view 常用extensions

<?php echo chtml::link(chtml::encode('link'), array('view', 'id'=>$data->id)); ?>  

 阿薩德發