// Usually
public function actionIndex($cityId)
{
if (is_null($city = City::findOne(['id' => intval($cityId)]))) {
throw new HttpExceprion(404);
}
return $city;
}
// Now
public function actionIndex(City $city)
{
return $city;
}
// Or
/**
* @validate
* @param \app\models\City $city
*/
public function actionIndexNew($city)
{
return $city;
}
// Or
/**
* @validate
* @param City $city
*/
public function actionIndexNew(City $city)
{
return $city;
}
public function beforeAction($action)
{
if (!parent::beforeAction($action)) {
throw new HttpException(404);
}
return true;
}
// If user is guest, Error 404
public function actionIndexNew(User $user)
{
// Error 404
}
// If user is login, User::findOne(['id' => \Yii::$app->user->id])
public function actionIndexNew(User $user)
{
return $user;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.