Last active
December 31, 2015 16:09
-
-
Save jawinn/8012137 to your computer and use it in GitHub Desktop.
loadModelSlug, Yii - from clean URL tutorial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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