开发者

CakePHP route URL not found!

开发者 https://www.devze.com 2023-02-19 14:01 出处:网络
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:

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


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!


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.


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消