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


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.


$this->widget('bootstrap.widgets.TbExtendedGridView', array(
'ajaxUrl'=> $this->createUrl('/forms/index'),
'responsiveTable' => true,
'name' => 'forms_status',
'filter' => CHtml::activeDropDownList($model, 'forms_status', CHtml::listData($YOUR-ARRAY,'id','attributes_name'), array(
'multiple' => 'multiple'