public function loadModel($id)
{
$model=Postdata::model()->findByPk($id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}
same in yii2 we are using
protected function findModel($id)
{
if (($model = Country::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}