Yii model default DB values

Great tip if your working with the PHP-framework Yii, if you create a new model and want to set some default values, like ”order by”, you can just add the following function (defaultScope) to your CActiveRecord extended class:

public function defaultScope(){
return array(
‘order’=>’my_order_field DESC’
);
}

Read more here: http://www.yiiframework.com/doc/guide/1.1/en/database.ar

Annonser

Yii dropdown multiple select TbExtendedGridView and CGridView

If you want to use a multiple selectbox for your CGridView or TbExtendedGridView, just use activeDropDownList as a filter and add array(‘multiple’ => ‘multiple’) as a third parameter.

Example:


$this->widget('bootstrap.widgets.TbExtendedGridView', array(
'id'=>'forms-grid',
'dataProvider'=>$dataProvider,
'filter'=>$model,
'ajaxUrl'=> $this->createUrl('/forms/index'),
'responsiveTable' => true,
'columns'=>array(
array(
'name' => 'forms_status',
'type'=>'raw',
'filter' => CHtml::activeDropDownList($model, 'forms_status', CHtml::listData($YOUR-ARRAY,'id','attributes_name'), array(
'multiple' => 'multiple'
)),
'value'=>'Attributes::model()->getAttributeName($data->forms_status);',

),
)));