Missing Action Method

Hi everyone !

Does yii2 have a methodlike missingAction() method from previous version of Yii ?

In previous version it was something like this :

public function missingAction() {

    throw new CustomException(self::MISSING_ACTION_CODE, self::MISSING_ACTION);


}

Thank you!

I’m not sure, but there was a discussion about it and the answer was “no”.

See the possible implementation proposed by Cebe.




url rules:


// other rules here

'user/<action>' => 'user/missing',

'<controller>/<action>' => 'site/missing',

controllers:


class UserController

{

    public function actionMissing($action)

    {

        // do whatever you want

    }

}


class SiteController

{

    public function actionMissing($controller, $action)

    {

        // do whatever you want

    }

}



would be cool if you could describe your use case for it.

I would like to throw an exception every time I request a missing action , just for one controller’s missing actions .

can you please elaborate a bit more what this one controller is about? We really need use cases for this to be able to create a good solution.

I have a controller and I would like to customize when someone request an action that doesn’t exit .

This controller has three actions . I would like to handle in my way any bad request.

Now if I call a missing action I get an 404 error Unable to resolve the request:

Something like this : domain/index.php/controller_name/missing_action and the response to be customize . Let’s say I would like to get : My error bad request.