Skip to content

Instantly share code, notes, and snippets.

@jawinn
Last active December 31, 2015 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jawinn/8012137 to your computer and use it in GitHub Desktop.
Save jawinn/8012137 to your computer and use it in GitHub Desktop.
loadModelSlug, Yii - from clean URL tutorial
public function actionView($slug)
{
$this->render('view',array(
'model'=>$this->loadModelSlug($slug),
));
}
public function loadModelSlug($slug)
{
$model = Product::model()->findByAttributes(array('slug'=>$slug));
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment