0

In Bootstrap.php I have some custom routes using Zend_Controller_Router_Route_Regex. Everything works fine except when user type in address bar a wrong link.

Ex :

http://mysite/en/1-some-article.html => This is a valid link that matches a ROUTE in Bootstrap.

But when user make a typo mistake like:

http://mysite/en/1-some-article.**html'** or http://mysite/en/1-some-article.**hhtml** , they are not match any ROUTE in Bootstrap, then Zend Framework throws an exception like : No route matched the request

Is there anyway to handle it, like redirecting to a custom page for "No matched routes"?

Any help will be appreciated. Thanks for advance!

Configuration (from comment below)

[production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
phpSettings.date.timezone = "Europe/London"
;includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = ""
;resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules = ""
autoloaderNamespaces.Fxml = "Mycms_"
autoloaderNamespaces.Fxml = "Fxml_"
Siguza
  • 21,155
  • 6
  • 52
  • 89
Nấm Lùn
  • 1,277
  • 6
  • 28
  • 48
  • In your production environment, you would set `resources.frontController.params.throwExceptions` to false. This will cause the error to fall through to the `ErrorController`. See http://framework.zend.com/manual/1.12/en/zend.controller.plugins.html#zend.controller.plugins.standard.errorhandler.fourohfour and http://framework.zend.com/manual/1.12/en/zend.controller.exceptions.html – Phil Nov 01 '12 at 03:55
  • @Phil : I do have that line in my application.ini but nothing changed. – Nấm Lùn Nov 01 '12 at 03:58
  • And you're running your app with prod settings? – Phil Nov 01 '12 at 03:59
  • @Phil : Yes,Im running the app with [production] settings. – Nấm Lùn Nov 01 '12 at 04:01
  • Could you `var_dump()` the value of the `APPLICATION_ENV` constant, just to make sure? – Phil Nov 01 '12 at 04:08
  • @quangtruong1985 : did you override the default routing? – prodigitalson Nov 01 '12 at 04:13
  • @Phil : Yep, this is what I get in Bootstrap.php with Zend_Debug::dump(APPLICATION_ENV) : string(10) "production" – Nấm Lùn Nov 01 '12 at 04:19
  • Can you add the relevant sections of your config file (`application.ini`) to your question? – Phil Nov 01 '12 at 04:20
  • @prodigitalson : Yes, I did. I replaced it with this: $defaultRoute = new Zend_Controller_Router_Route_Regex( '', array( 'module' => 'default', 'controller' => 'index', 'action' => 'index' ), array( ), 'trang-chu.html' ); $defaultRoute = $langRoute->chain($defaultRoute); – Nấm Lùn Nov 01 '12 at 04:20
  • @quangtruong1985 Please don't post that stuff in comments. I've edited your question with the extra information. – Phil Nov 01 '12 at 05:28

1 Answers1

0

To make use of the ErrorController, you need to set the front controller throwExceptions attribute to false. Put this in your [production] configuration section

resources.frontController.params.throwExceptions = 0

See http://framework.zend.com/manual/1.12/en/zend.controller.exceptions.html and http://framework.zend.com/manual/1.12/en/zend.controller.plugins.html#zend.controller.plugins.standard.errorhandler.fourohfour.

I mentioned this in the comments above but you seem to have missed it (you have displayExceptions set to false but not throwExceptions).

Phil
  • 157,677
  • 23
  • 242
  • 245
  • Yeah, I put that line into my application.ini but nothing changed, too. The system keep throwing the exception. – Nấm Lùn Nov 01 '12 at 05:36