Difference between #2 and #1 of Inline views, write less

unchanged
Title
Inline views, write less
unchanged
Category
Tips
unchanged
Tags
active record, URL, model, views
changed
Content
Sometimes writing views like 

~~~
[php]
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...


~~~
[php]
class MyModel extends CActiveRecord
{


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