0

The last connect on the Lithium Router:

Router::connect('/{:controller}/{:action}/{:args}', 'Main::end');

Should match all the routes? No? But instead of execute my Main::end method (who simply exit('with some text, for testing...')), Lithium give to me a dispatcher exception T_T:

 lithium\action\DispatchException (code 404)
 Controller `Sdsa` not found.
 path_to_my_root/libraries/lithium/action/Dispatcher.php: 239

What i'm doing wrong?

Oerd
  • 2,256
  • 1
  • 21
  • 35
cl0udw4lk3r
  • 2,663
  • 5
  • 26
  • 46
  • The last router entry match a controller and a function. so `/User/List` would match the `User` controller and the function `List` in that controler. What you got above is a 404, and to change that you override the 404 message sent to the user. – Nils Jan 14 '13 at 13:50
  • But I passed as second parameter the Main::end controller->action... By the way... I solved that, I will post the solution! – cl0udw4lk3r Jan 14 '13 at 18:54

1 Answers1

0

Solved my self issue by using a standard regex:

Router::connect('/(.*)', 'Main::end');

that will process all the requests to Main::end.

As Nils says, my actual solution is not perfect because of the lack of 404 pages handling...

Because i'm trying to use Backbone.js, maybe i could handle the 404 pages client side like this: How to have a fallback route to catch unknown pages in backbone.js

Community
  • 1
  • 1
cl0udw4lk3r
  • 2,663
  • 5
  • 26
  • 46
  • Please note that not sending 404:s, and other errors might be confusing to users. For example if they misspell an URL. Also, search engines will become confused if a page is removed, as you are not returning a 404 for a missing page. If doing this to create a 404, then you can just edit `views\layouts\error.html.php`. Here is a note from Google regarding 404/410 (and soft 404:s) http://googlewebmastercentral.blogspot.se/2011/05/do-404s-hurt-my-site.html – Nils Jan 14 '13 at 19:57
  • The problem is I'm trying to implement Backbone.js with lithium, and for now i only need the home as homepage (instead of Main::end now is Main::home...), but what u say is right, maybe i should route the home from backbone directly, or insert backbone.js on all the lithium layouts... – cl0udw4lk3r Jan 15 '13 at 00:43
  • @cl0udw4lk3r: lithium responses can be rendered very easily as JSON objects by adding the proper `{:type}` placeholder in the route. The preferred way is [content-negotiating](http://sphere.lithify.me/p/Li3-Advent-Day-3) – Oerd Jan 22 '13 at 09:54