loadModel

I noticed in Yii 1 many people where using a loadModel in their controllers to load the model for the controller.

I was wondering if anyone is still doing this in Yii 2?

I personally never did it, either in Yii 1 or Yii 2, but just wondered whether this was just a Yii 1 thing or are people doing it in Yii 2?

loadmodel is function to get modal data


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.');

        }

    }