Site building and maintenance

Blog

Search

Tips for Yii. Сhapter 6

Tips for Yii. Сhapter 6.

Advice on Yii. Сhapter 5

Advice on Yii. Сhapter 5.

Tips for Yii. Сhapter 4

Tips for Yii. Сhapter 4.

Tips for Yii. Сhapter 3

Tips for Yii. Сhapter 3.

  1. A grouped dropdown list.

    The first option:

    1. echo CHtml::dropDownList('Cars''car_id'array(  
    2.     'Toyota'=>array(  
    3.         1=>'Avensis',  
    4.         2=>'Camry',  
    5.     ),  
    6.     'Volvo'=>array(  
    7.         3=>'S60',  
    8.         4=>'XC70',  
    9.     ),  
    10. ));  

    The second option:

    1. $records = array(  
    2.     array('id' => 1, 'name' => 'Yii''group' => 'Framework'),  
    3.     array('id' => 2, 'name' => 'Drupal''group' => 'Framework'),  
    4.     array('id' => 3, 'name' => 'Joomla''group' => 'Framework'),  
    5.     array('id' => 4, 'name' => 'Сodeigniter''group' => 'Framework'),  
    6.     array('id' => 5, 'name' => 'Mercurial''group' => 'Version control system'),  
    7.     array('id' => 6, 'name' => 'Git''group' => 'Version control system'),  
    8.     array('id' => 7, 'name' => 'SVN''group' => 'Version control system'),  
    9. );  
    10.   
    11. $dropDownList = CHtml::listData($records'id''name''group');   
    12. echo CHtml::dropDownList('dropDownList'''$dropDownList);  

     

Tips for Yii. Сhapter 2

We continue to tell you about some interesting moments which you can meet during web development based on a Yii framework.

  1. Behaviors.

    Often while adding a new code or updating an existing one, you need to update the field in the table, for example date_updated / date_created.

    For this purpose you should add in the model:

     

    1. public function behaviors(){  
    2.     return array(  
    3.         'AutoTimestampBehavior' => array(  
    4.             'class' => 'zii.behaviors.CTimestampBehavior',  
    5.             'createAttribute' => 'date_updated',  
    6.             'updateAttribute' => 'date_updated',  
    7.         ),  
    8.     );  
    9. }  

     Now by adding or updating the code the field date_updated will be filled with actual value automatically.

Tips for Yii. Сhapter 1

There are many unclear points by developing any product, to find an answer for them you use Google or follow the advice given by your colleagues, or read manuals.

We would like to help you and to save your time, in case you have the same problems.