Monday, August 22, 2011

Learning Yii Relational Active Record

I'm a newbie in YII framework. But after exploring the  framework. I can conclude that is coolest framework of PHP. :)

In YII all DB tables can be represented by a model class. Where you can set rule and restrict some table column.

One thing I impress of YII is there Active Record feature. Instead of declaring the sql command to query the data of two or more tables. In YII we can just create relation function  in the model class to join the tables by assigning the  foreign keys.

see details here

Ajax button in YII

Jquery was already  integrated in Yii Framework, we dont need to link the jquery library on   Yii apps.

Example using ajax in yii. All we need to do is familiar  the  ajax tags and how it in jquery, because it work same way and tags same way in yii with there button, submit even  in link.

It is format this way. ie. ajax button.

Chtml - form tag of yii
ajaxButton - ajax button tag

Chtml::ajaxButton (
        'Button Label',   - //Label on the button
        ' array('URL')',   - // this the url of the proccess file... or use call the action function of the current controller.
       ' type' => 'post'  - // method type Post or GET
        'data' =>array(), - // Data you want to send to copntroller.. must be in array
        'success' => 'function(data) { ---Do somthing here-- }',

Tips: You can remove the data array if you working with a form.