Implement support for handling missing action and/or controller #754

Closed
rawtaz opened this Issue Aug 13, 2013 · 32 comments

Comments

Projects
None yet
@rawtaz
Contributor

rawtaz commented Aug 13, 2013

A common use case ppl ask about now and then is that they want a certain action and/or controller to kick in when the requested action and/or controller doesn't exist.

In Yii 1.1 there was missingAction() that could be used for the former, but it's currently not in the Yii2 code base. There was AFAIK nothing for the controller part (the defaultController setting is not the same, as it only kicks in when no specific controller was requested).

I was about to write some stuff about the implementation details, but @cebe says he already has it covered, so I'll let him fill in the blanks :)

@rawtaz

This comment has been minimized.

Show comment
Hide comment
@rawtaz

rawtaz Aug 13, 2013

Contributor

The simplest use of missingController() as it is now is to do something like this inside it, right?

return $this->runAction('route/to/run/instead/of/the/missing/one');

But as we're already in/under runAction(), the new route must really exist or we'll hit a loop (which will probably be terminated by PHP, causing a blank page or such). Hence, checking needs to be done to be sure, and that would end up being a bunch of code which is what we wanted to get rid of in the first place (by adding missingController()).

Wouldn't it be nicer if there was a setting named $missingController (sibling to $defaultController) where one could put a route, and the default implementation of missingController() did a check to make sure that controller exists and if it does runs it, otherwise returns false so we get the regular error/404?

I think the latter is what people asking about this use case would want. Just a simple setting to define which controller to run if an invalid request comes in, nothing fancier than that.

Contributor

rawtaz commented Aug 13, 2013

The simplest use of missingController() as it is now is to do something like this inside it, right?

return $this->runAction('route/to/run/instead/of/the/missing/one');

But as we're already in/under runAction(), the new route must really exist or we'll hit a loop (which will probably be terminated by PHP, causing a blank page or such). Hence, checking needs to be done to be sure, and that would end up being a bunch of code which is what we wanted to get rid of in the first place (by adding missingController()).

Wouldn't it be nicer if there was a setting named $missingController (sibling to $defaultController) where one could put a route, and the default implementation of missingController() did a check to make sure that controller exists and if it does runs it, otherwise returns false so we get the regular error/404?

I think the latter is what people asking about this use case would want. Just a simple setting to define which controller to run if an invalid request comes in, nothing fancier than that.

@rawtaz

This comment has been minimized.

Show comment
Hide comment
@rawtaz

rawtaz Aug 13, 2013

Contributor

On second thought, perhaps that/such a setting should be a route including action if needed, and not just a route to a controller.

Contributor

rawtaz commented Aug 13, 2013

On second thought, perhaps that/such a setting should be a route including action if needed, and not just a route to a controller.

@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Aug 13, 2013

Member

Any examples when missingAction can be used?

If missingAction doesn't need to reside in a particular controller, then we should consider handling InvalidRouteException in Module::runAction(), which deals with both controller and action missing cases.

Member

qiangxue commented Aug 13, 2013

Any examples when missingAction can be used?

If missingAction doesn't need to reside in a particular controller, then we should consider handling InvalidRouteException in Module::runAction(), which deals with both controller and action missing cases.

@cebe

This comment has been minimized.

Show comment
Hide comment
@cebe

cebe Aug 13, 2013

Member

The simplest use of missingController() as it is now is to do something like this inside it, right?

No, you have to return a controller or action instance.

Member

cebe commented Aug 13, 2013

The simplest use of missingController() as it is now is to do something like this inside it, right?

No, you have to return a controller or action instance.

@rawtaz

This comment has been minimized.

Show comment
Hide comment
@rawtaz

rawtaz Aug 13, 2013

Contributor

@qiangxue The use case for missingAction() is when foo/bar is requested but the Foo controller doesn't have an actionBar() in it. Then missingAction() would be called instead. A (potentially bad) example could be when changing the name of some action and wanting to catch requests to the old one to display a "this stuff moved, update your bookmarks!" page or similar. Perhaps doing some automated resolving of old -> new URLs.

Since an action will never be requested without a controller being specified, as I see it missingAction() would normally be something we define on a per-controller basis. If needing it in many controllers one can put a "common" missingAction() in a base controller class OR in a behavior (assuming that works with how PHP resolves methods).

Yeah, handling the situation was already doable using some overriding, but the purpose of this issue is to introduce a simpler way for people to handle this stuff, e.g. via some setting.

Contributor

rawtaz commented Aug 13, 2013

@qiangxue The use case for missingAction() is when foo/bar is requested but the Foo controller doesn't have an actionBar() in it. Then missingAction() would be called instead. A (potentially bad) example could be when changing the name of some action and wanting to catch requests to the old one to display a "this stuff moved, update your bookmarks!" page or similar. Perhaps doing some automated resolving of old -> new URLs.

Since an action will never be requested without a controller being specified, as I see it missingAction() would normally be something we define on a per-controller basis. If needing it in many controllers one can put a "common" missingAction() in a base controller class OR in a behavior (assuming that works with how PHP resolves methods).

Yeah, handling the situation was already doable using some overriding, but the purpose of this issue is to introduce a simpler way for people to handle this stuff, e.g. via some setting.

@rawtaz

This comment has been minimized.

Show comment
Hide comment
@rawtaz

rawtaz Aug 13, 2013

Contributor

@cebe Ok, makes sense. Does that make the other things I wrote make sense, too? That if we need to write a bit of code there's not much gain in missingController(), and a setting would be better?

Contributor

rawtaz commented Aug 13, 2013

@cebe Ok, makes sense. Does that make the other things I wrote make sense, too? That if we need to write a bit of code there's not much gain in missingController(), and a setting would be better?

@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Aug 13, 2013

Member

@rawtaz Your example of using missingAction() is not very convincing to me that it has to reside in a particular controller. A global handler can do similar task well too.

By handling InvalidRouteException in Module::runAction(), I actually meant to add some property to Module that users can customize to provide a central handler of InvalidRouteException. It would cover both missing controller and action cases.

Member

qiangxue commented Aug 13, 2013

@rawtaz Your example of using missingAction() is not very convincing to me that it has to reside in a particular controller. A global handler can do similar task well too.

By handling InvalidRouteException in Module::runAction(), I actually meant to add some property to Module that users can customize to provide a central handler of InvalidRouteException. It would cover both missing controller and action cases.

@rawtaz

This comment has been minimized.

Show comment
Hide comment
@rawtaz

rawtaz Aug 13, 2013

Contributor

@qiangxue I don't have a strong opinion about where or how missingAction() should be, and I do see your point.

Let's say that missingAction() is not defined in the controller. So the request becomes handled by the "central handler". If there is now a need to have different "missingAction" handling depending on which controller was requested, one probably needs to write some logic that inspects the requested controller ID and does whatever is appropriate based on that, right? If that's the case, I feel this is not as flexible as being able to define missingAction() in individual controllers (instead of defining missingAction handling where you want/need it, you need to write code to point the handling to the right place). However, indeed it becomes a question about what use cases there are for having it in the controller level.

I think it's important that however invalid requests for controllers and/or actions are handled, users are able to write regular controllers and actions to do it (as opposed to overriding some handler method to create/call some controller/action themselves). Hence my focus on this being more of a configuration approach than a coding approach, if you see what I mean.

Contributor

rawtaz commented Aug 13, 2013

@qiangxue I don't have a strong opinion about where or how missingAction() should be, and I do see your point.

Let's say that missingAction() is not defined in the controller. So the request becomes handled by the "central handler". If there is now a need to have different "missingAction" handling depending on which controller was requested, one probably needs to write some logic that inspects the requested controller ID and does whatever is appropriate based on that, right? If that's the case, I feel this is not as flexible as being able to define missingAction() in individual controllers (instead of defining missingAction handling where you want/need it, you need to write code to point the handling to the right place). However, indeed it becomes a question about what use cases there are for having it in the controller level.

I think it's important that however invalid requests for controllers and/or actions are handled, users are able to write regular controllers and actions to do it (as opposed to overriding some handler method to create/call some controller/action themselves). Hence my focus on this being more of a configuration approach than a coding approach, if you see what I mean.

@rawtaz

This comment has been minimized.

Show comment
Hide comment
@rawtaz

rawtaz Aug 13, 2013

Contributor

If anyone reading this is using missingAction(), please let us know what your use case is / what you use it for!

Contributor

rawtaz commented Aug 13, 2013

If anyone reading this is using missingAction(), please let us know what your use case is / what you use it for!

@qiangxue

This comment has been minimized.

Show comment
Hide comment
@qiangxue

qiangxue Aug 13, 2013

Member

Yes, it really depends on the actual need of missingAction.

Typically if URL redirection is needed for site migration and SEO purpose, a central place to do this is more manageable than scattering it in different places. Parsing a route shouldn't be too big a trouble as its format is simple enough, unlike URLs.

I'm not sure if we should use an action to handle this thing. Anonymous function seems less restrictive than action.

Member

qiangxue commented Aug 13, 2013

Yes, it really depends on the actual need of missingAction.

Typically if URL redirection is needed for site migration and SEO purpose, a central place to do this is more manageable than scattering it in different places. Parsing a route shouldn't be too big a trouble as its format is simple enough, unlike URLs.

I'm not sure if we should use an action to handle this thing. Anonymous function seems less restrictive than action.

@rawtaz

This comment has been minimized.

Show comment
Hide comment
@rawtaz

rawtaz Aug 13, 2013

Contributor

I think we don't need to hurry with this; Let's see what other people have to say about it.

Contributor

rawtaz commented Aug 13, 2013

I think we don't need to hurry with this; Let's see what other people have to say about it.

@samdark

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark Oct 14, 2013

Member

Using action doesn't seem right to me. This action isn't really an action but something like a callback.

Member

samdark commented Oct 14, 2013

Using action doesn't seem right to me. This action isn't really an action but something like a callback.

@cebe

This comment has been minimized.

Show comment
Hide comment
@cebe

cebe Dec 17, 2013

Member

As far as I see right now this should all be manageable using url rules. We can define rules that match our existing controllers and then define one that matches the rest. I currently see no need for missing action feature unless I see a use case.

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
    }
}
Member

cebe commented Dec 17, 2013

As far as I see right now this should all be manageable using url rules. We can define rules that match our existing controllers and then define one that matches the rest. I currently see no need for missing action feature unless I see a use case.

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
    }
}

@cebe cebe closed this Dec 17, 2013

@klimov-paul

This comment has been minimized.

Show comment
Hide comment
@klimov-paul

klimov-paul Dec 17, 2013

Member

We can define rules that match our existing controllers and then define one that matches the rest. I currently see no need for missing action feature unless I see a use case.

Such solution will extend the list of URL rules, which is not good. Each URL rule check requires regular expression match execution. So many rules will hit the performance.

I think the solution for this issue can be composed into an event “onMissingAction”, which controller should introduce. If the event is not handled, the default “404 page” flow should be performed.

Member

klimov-paul commented Dec 17, 2013

We can define rules that match our existing controllers and then define one that matches the rest. I currently see no need for missing action feature unless I see a use case.

Such solution will extend the list of URL rules, which is not good. Each URL rule check requires regular expression match execution. So many rules will hit the performance.

I think the solution for this issue can be composed into an event “onMissingAction”, which controller should introduce. If the event is not handled, the default “404 page” flow should be performed.

@cebe

This comment has been minimized.

Show comment
Hide comment
@cebe

cebe Dec 17, 2013

Member

Do you have any good use case for it? Also the question is on which object this event should fire.

Member

cebe commented Dec 17, 2013

Do you have any good use case for it? Also the question is on which object this event should fire.

@cebe

This comment has been minimized.

Show comment
Hide comment
@cebe

cebe Dec 17, 2013

Member

Also note that this kind of rule might be one of the last in the list so it does not have an impact on performance when you access non missing action.

Member

cebe commented Dec 17, 2013

Also note that this kind of rule might be one of the last in the list so it does not have an impact on performance when you access non missing action.

@klimov-paul

This comment has been minimized.

Show comment
Hide comment
@klimov-paul

klimov-paul Dec 17, 2013

Member

Also note that this kind of rule might be one of the last in the list so it does not have an impact on performance when you access non missing action.

Normally I am using rule like:

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

which covers many different controllers: 'user', 'item' etc.

In order to apply rule:

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

I need to specify as many rules as I have controllers before it in the list.

Do you have any good use case for it?

Back in Yii1 I used “missingAction()” to handle outdated URLs, which required 301 redirection.

Member

klimov-paul commented Dec 17, 2013

Also note that this kind of rule might be one of the last in the list so it does not have an impact on performance when you access non missing action.

Normally I am using rule like:

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

which covers many different controllers: 'user', 'item' etc.

In order to apply rule:

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

I need to specify as many rules as I have controllers before it in the list.

Do you have any good use case for it?

Back in Yii1 I used “missingAction()” to handle outdated URLs, which required 301 redirection.

@cebe cebe reopened this Dec 17, 2013

@qiansen1386

This comment has been minimized.

Show comment
Hide comment
@qiansen1386

qiansen1386 Dec 19, 2013

Contributor

Is that a customized 404 action?

2013/12/17 Carsten Brandt notifications@github.com

Reopened #754 #754.


Reply to this email directly or view it on GitHubhttps://github.com/yiisoft/yii2/issues/754
.

Contributor

qiansen1386 commented Dec 19, 2013

Is that a customized 404 action?

2013/12/17 Carsten Brandt notifications@github.com

Reopened #754 #754.


Reply to this email directly or view it on GitHubhttps://github.com/yiisoft/yii2/issues/754
.

@cebe

This comment has been minimized.

Show comment
Hide comment
@cebe

cebe Dec 19, 2013

Member

Can be. But not limited to 404. We are still searching for use cases.

Member

cebe commented Dec 19, 2013

Can be. But not limited to 404. We are still searching for use cases.

@qiangxue qiangxue modified the milestones: 2.0 RC, 2.0 GA Apr 16, 2014

@Memorywipe

This comment has been minimized.

Show comment
Hide comment
@Memorywipe

Memorywipe May 12, 2014

One of the use cases that I have used this for is when I need dynamic handling of actions within a controller, but these actions define something.

For example, for a profile system. http://example.com/profile/cebe

profile is the controller, and cebe is the action, where it does not exist as an action but rather handled at runtime to retrieve information based on the action passed, in this use case, a username.

One of the use cases that I have used this for is when I need dynamic handling of actions within a controller, but these actions define something.

For example, for a profile system. http://example.com/profile/cebe

profile is the controller, and cebe is the action, where it does not exist as an action but rather handled at runtime to retrieve information based on the action passed, in this use case, a username.

@sdacunha

This comment has been minimized.

Show comment
Hide comment
@sdacunha

sdacunha May 12, 2014

I am in a similar situation as Memorywipe, needing user-profiles to be handled, where the action passed acts as a parameter for the view's content.

I know that Module::runAction can be overridden, and there are a multitude of other ways to handle this, but I feel that in Yii 1.x the missingAction approach was simplistic and straightforward. I only need one specific controller to have this behavior.

I am in a similar situation as Memorywipe, needing user-profiles to be handled, where the action passed acts as a parameter for the view's content.

I know that Module::runAction can be overridden, and there are a multitude of other ways to handle this, but I feel that in Yii 1.x the missingAction approach was simplistic and straightforward. I only need one specific controller to have this behavior.

@cebe

This comment has been minimized.

Show comment
Hide comment
@cebe

cebe May 17, 2014

Member

@Memorywipe @shadwelldacunha you should better use url routing to achive such behavior.

Member

cebe commented May 17, 2014

@Memorywipe @shadwelldacunha you should better use url routing to achive such behavior.

@sdacunha

This comment has been minimized.

Show comment
Hide comment
@sdacunha

sdacunha May 17, 2014

@cebe @Memorywipe I haven't taken a look at the new URL routing system, could you possibly give me an example?

Currently I override runAction; checking if the action is not null to pass it onto parent::runAction(), else checking if a user with that ID exists (if not, throw an InvalidRouteException, so basically the same behaviour as the parent class, with an extra test case).

This is probably not the best way to handle this, so I'm interested to know how I could achieve this with url routing.

@cebe @Memorywipe I haven't taken a look at the new URL routing system, could you possibly give me an example?

Currently I override runAction; checking if the action is not null to pass it onto parent::runAction(), else checking if a user with that ID exists (if not, throw an InvalidRouteException, so basically the same behaviour as the parent class, with an extra test case).

This is probably not the best way to handle this, so I'm interested to know how I could achieve this with url routing.

@cebe

This comment has been minimized.

Show comment
Hide comment
@cebe

cebe May 17, 2014

Member

Url management rules are very similar to yii 1.1. check the guide: http://www.yiiframework.com/doc-2.0/guide-url.html

Member

cebe commented May 17, 2014

Url management rules are very similar to yii 1.1. check the guide: http://www.yiiframework.com/doc-2.0/guide-url.html

@sdacunha

This comment has been minimized.

Show comment
Hide comment
@sdacunha

sdacunha May 17, 2014

@cebe Oh I see, that's great, should work fine. Thanks!
Loving Yii2 so far, this was the only "hiccup" I had when transitioning.

@cebe Oh I see, that's great, should work fine. Thanks!
Loving Yii2 so far, this was the only "hiccup" I had when transitioning.

@cebe

This comment has been minimized.

Show comment
Hide comment
@cebe

cebe Jun 25, 2014

Member

closing this as there is no clear issue or task. When there is a need we can open a new issue.

Member

cebe commented Jun 25, 2014

closing this as there is no clear issue or task. When there is a need we can open a new issue.

@cebe cebe closed this Jun 25, 2014

@cebe cebe removed this from the 2.0 RC milestone Jun 25, 2014

@lubosdz

This comment has been minimized.

Show comment
Hide comment
@lubosdz

lubosdz Mar 3, 2015

Contributor

Missing action should be supported also in Yii2.
Here's use case from our current project:

  • we have CMS static pages in database, that are added by a customer. Customer adds HTML + link identifier, e.g. link="privacy-terms"
  • we never know, what static page will customer add, but we always want to have pretty URL, like www.site.com/privacy-terms
  • we cannot add rule into /config/web.php because there is lots of static pages and we cannot update server any time.
  • our current solution is to catch missing route in "actionError" do database check and if we have database match against $_GET['action'], we will return HTML content from DB. The problem is, headers always set 404 - page not found, even though HTML output is corrent. If database no match, we will run error. Here is modified error handler:
public function actionError()
{
    // check whether we have any searched term (slug)
    $slug = empty($_GET['action']) ? '' : htmlspecialchars($_GET['action']);
    $exception = Yii::$app->errorHandler->exception;
    if($exception instanceof \yii\web\NotFoundHttpException && $slug){
        // we have missing page, let's try to find static content
        $page = StaticPage::findOne(['slug' => $slug]);
        if($page){
            // OK, found static page
            return $this->render('static', ['model' => $page]);
        }
    }
    return (new \yii\web\ErrorAction('error', $this))->run();
}
  • if we could check the database BEFORE throwing error, that would be best solution for us. No need to modify error handler, and no 404 headers.

Or can you suggest how to implement this in a proper way without missingAction support?
Thank you very much.

Contributor

lubosdz commented Mar 3, 2015

Missing action should be supported also in Yii2.
Here's use case from our current project:

  • we have CMS static pages in database, that are added by a customer. Customer adds HTML + link identifier, e.g. link="privacy-terms"
  • we never know, what static page will customer add, but we always want to have pretty URL, like www.site.com/privacy-terms
  • we cannot add rule into /config/web.php because there is lots of static pages and we cannot update server any time.
  • our current solution is to catch missing route in "actionError" do database check and if we have database match against $_GET['action'], we will return HTML content from DB. The problem is, headers always set 404 - page not found, even though HTML output is corrent. If database no match, we will run error. Here is modified error handler:
public function actionError()
{
    // check whether we have any searched term (slug)
    $slug = empty($_GET['action']) ? '' : htmlspecialchars($_GET['action']);
    $exception = Yii::$app->errorHandler->exception;
    if($exception instanceof \yii\web\NotFoundHttpException && $slug){
        // we have missing page, let's try to find static content
        $page = StaticPage::findOne(['slug' => $slug]);
        if($page){
            // OK, found static page
            return $this->render('static', ['model' => $page]);
        }
    }
    return (new \yii\web\ErrorAction('error', $this))->run();
}
  • if we could check the database BEFORE throwing error, that would be best solution for us. No need to modify error handler, and no 404 headers.

Or can you suggest how to implement this in a proper way without missingAction support?
Thank you very much.

@samdark

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark Mar 3, 2015

Member

@lubosdz it's old closed issue. Not a good idea to post in its comments...

Member

samdark commented Mar 3, 2015

@lubosdz it's old closed issue. Not a good idea to post in its comments...

@adimittal

This comment has been minimized.

Show comment
Hide comment
@adimittal

adimittal Jul 20, 2015

I really think we should reopen this and add support for missingAction. I have whole applications in yii1 where missing action is absolutely the crux of not writing thousands of useless lines of code in controllers. Trying to extend yii\base\module has not been working out either. Yii is simply assuming missingAction means error, but it doesn't. I don't want to default to missing action = error, but to missing action => check if a view with the action name exists, if it does render that view. Why should I be forced to write code that's not DRY and adds no value.

I really think we should reopen this and add support for missingAction. I have whole applications in yii1 where missing action is absolutely the crux of not writing thousands of useless lines of code in controllers. Trying to extend yii\base\module has not been working out either. Yii is simply assuming missingAction means error, but it doesn't. I don't want to default to missing action = error, but to missing action => check if a view with the action name exists, if it does render that view. Why should I be forced to write code that's not DRY and adds no value.

@adimittal

This comment has been minimized.

Show comment
Hide comment
@adimittal

adimittal Jul 20, 2015

Here is how I solved it:

In my BaseController I made an actionMissing:

/**
   * Override Yii if the action is missing
   * @param type $actionID
   */
  public function actionMissing($actionID = '') {
    if($actionID == ''){
      $actionID = $_GET['action'];
    }
    $action = 'action' . ucfirst($actionID); // $actionName with first lette is uppercase
    $actionExists = method_exists($this, $action);
    if($actionExists){
      return $this->$action();
    }
    try {
      return $this->render($actionID);
    }
    catch (\yii\base\Exception $e) {
      echo "Sorry $actionID action or view not found.";
    }
  }

I then route all controller actions to the missing action. I check if the action exists, if so I route it there. Otherwise I handle it however I want. Routing to missing action is simply adding a url manager rule in config:

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

Though it creates an extra step in the routing.

Here is how I solved it:

In my BaseController I made an actionMissing:

/**
   * Override Yii if the action is missing
   * @param type $actionID
   */
  public function actionMissing($actionID = '') {
    if($actionID == ''){
      $actionID = $_GET['action'];
    }
    $action = 'action' . ucfirst($actionID); // $actionName with first lette is uppercase
    $actionExists = method_exists($this, $action);
    if($actionExists){
      return $this->$action();
    }
    try {
      return $this->render($actionID);
    }
    catch (\yii\base\Exception $e) {
      echo "Sorry $actionID action or view not found.";
    }
  }

I then route all controller actions to the missing action. I check if the action exists, if so I route it there. Otherwise I handle it however I want. Routing to missing action is simply adding a url manager rule in config:

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

Though it creates an extra step in the routing.

@Hoszi

This comment has been minimized.

Show comment
Hide comment
@Hoszi

Hoszi Mar 11, 2016

My solution is to rewrite the \vendor\yiisoft\yii2\base\Module.php createController function.
before a last return section insert this code:
if($controller === null && $route == '') { $controller = $this->createControllerByID('site'); $route = 'missing'; }
Is there any other proper solution? But i think this could be a good way to handle the missing action.

Hoszi commented Mar 11, 2016

My solution is to rewrite the \vendor\yiisoft\yii2\base\Module.php createController function.
before a last return section insert this code:
if($controller === null && $route == '') { $controller = $this->createControllerByID('site'); $route = 'missing'; }
Is there any other proper solution? But i think this could be a good way to handle the missing action.

@adimittal

This comment has been minimized.

Show comment
Hide comment
@adimittal

adimittal Mar 11, 2016

You shouldn't change the actual library, maybe extending in your own code
is okay. Changing the actual library is bad because the code will break on
library updates etc.

The solution I used is I defined actionMissing in my abstract class, which
is always hit first

On Fri, Mar 11, 2016 at 4:28 AM, Hoszi notifications@github.com wrote:

My solution is to rewrite the \vendor\yiisoft\yii2\base\Module.php
createController function.
before a last return section insert this code:
if($controller === null && $route == '')
{
$controller = $this->createControllerByID('site');
$route = 'missing';
}
Is there any other proper solution? But i think this could be a good way
to handle the missing action.


Reply to this email directly or view it on GitHub
#754 (comment).

Aditya Mittal
www.scientificchess.com
"Champions of the Mind" - http://championsofthemind.blogspot.com

You shouldn't change the actual library, maybe extending in your own code
is okay. Changing the actual library is bad because the code will break on
library updates etc.

The solution I used is I defined actionMissing in my abstract class, which
is always hit first

On Fri, Mar 11, 2016 at 4:28 AM, Hoszi notifications@github.com wrote:

My solution is to rewrite the \vendor\yiisoft\yii2\base\Module.php
createController function.
before a last return section insert this code:
if($controller === null && $route == '')
{
$controller = $this->createControllerByID('site');
$route = 'missing';
}
Is there any other proper solution? But i think this could be a good way
to handle the missing action.


Reply to this email directly or view it on GitHub
#754 (comment).

Aditya Mittal
www.scientificchess.com
"Champions of the Mind" - http://championsofthemind.blogspot.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment