CakePHP route URL not found!

天涯浪子 提交于 2019-12-11 03:55:42

问题


I am trying to do some custom routing on my site, but have been stuck for 2 days at a very silly issue. I have the following route configuration:

Router::connect('/your-solution/add-comment/*', array('controller' => 'comments', 'action' => 'add'));
Router::connect('/admin/your-solution/add-comment/*', array('controller' => 'comments', 'action' => 'add', 'admin' => true));

The problem is that when I try to load a URL formatted using the second route, it gives me a 404 not found. The first rule works fine.

For both rules I have a separate element containing a form and pointing to a URL formatted after the respective rule. The only parameter for both actions is the solution id, which is "contained" in the wildcard.

What could possibly be the issue? Thank you very much for your help!

EDIT:

I found out another weird behaviour. When I access /admin/your-solution/add-comment/3, it goes to that action. But if I submit a form to that link, it displays a blank page, with Firebug informing me that the page was not found. Very strange... Also, I have a similar route for editing comments. Both loading the edit form and saving the form work...


回答1:


how are you?

In order to see exactly why isn't it working, go to your /app/config/core.php and seek for this line:

Configure::write('debug', 2);

And make sure the value is set to "2". This way, it'll no longer give you a 404 error, but the actual issue, since in production mode (debug set to 0), all errors are masked with a 404 error.

Let me know!

Cheers!




回答2:


In your core.php be sure

Configure::write('Routing.prefixes', array('admin'));

In your comments controller, be sure you have

function admin_add() {...}

Also try other ways of formatting Routing statement.

Router::connect('/admin/your-solution/add-comment', array('controller' => 'comments', 'action' => 'add', 'admin' => true));

The order of your route is also important. You may want to check that.

For debugging which route you are using when loading the URL, try adding this code to your app_controller.php file.

function __construct() {
    $route = Router::currentRoute();
    pr($route);
}

These are just some tips to hopefully help you move forward.




回答3:


Apparently, the problem has been lying in a disabled input. After I've deleted this element, the form submits correctly and the target page is shown.

Just for my knowledge, why didn't the form submit if it had a disabled input in it?



来源:https://stackoverflow.com/questions/5434380/cakephp-route-url-not-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!