Quantcast
Channel: Live News for Yii Framework
Viewing all articles
Browse latest Browse all 3376

[Wiki] Inline views, write less

$
0
0

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($defaultView,array('slug'=>$this->slug),$options);
 else
   return($defaultView,array('id'=>$this->id),$options);
}
}

Viewing all articles
Browse latest Browse all 3376

Trending Articles