I have the following code to create a form in my app:
<?php echo $this->Form->create('User', array('action'=>'edit')); ?>
and it has a route like:
Router::connect('/settings', array('controller'=>'users','action'=>'edit'));
However the action is wrong…
<form action="/users/edit/6" method="post" accept-charset="utf-8">
If I put the form to defaults with:
<?php echo $this->Form->create(); ?>
then it fixes the routing issue, but why does specifying parameters break the routing???
When you specify in the create() parameters an actual URL – it will map to that url! The routes config doesn’t map backwards. For example – if you visit
/settings, it will load/editpage with the url still showing/settings. But if you visit/edit, it will show the url and will load the page/edit.So if you want your form action to map to /settings, don’t specify a url or use the url option
array('url' => '/settings')