Inline views, write less

3 followers

This wiki article has not been tagged with a corresponding Yii version yet.
Help us improve the wiki by updating the version information.

Sometimes writing views like

array('model/view','id'=>$model->id)

or something like this is too mainstream. Plus, sometimes we will need more than one ways to view models.

In this case I like below approach for my self. I often use slug so...

class MyModel extends CActiveRecord
{
 
 
public function url($options=array(),$defaultView='view')
{
 if($this->slug!=null)
   return array($defaultView,array('slug'=>$this->slug),$options);
 else
   return array($defaultView,array('id'=>$this->id),$options);
}
}

Be the first person to leave a comment

Please to leave your comment.

Write new article