On Fri, Jul 16, 2010 at 10:40 AM, Dunhamzzz <[email protected]> wrote:
> Hi
>
> In order to not have to duplicate my add and edit forms I have
> attempted to route all the admin_add actions to admin_edit, my
> admin_edit method is define to just load a blank form if no ID is
> supplied in the URL and this worked fine in CakePHP 1.2. I have
> however just upgraded to 1.3 for various reasons...
>
> I have tried the following in CakePHP 1.3 to no avail:
>
> Router::connect('/admin/:controller/add', array('action' => 'edit',
> 'admin' => true));
>
> What is the correct way to do this? Is there a better way then routing
> around the add action? It just seemed the easiest way, despite it
> making my admin_edit action a little bit more complicated.
Create elements for your forms and include them into each view as needed.
admin_add.ctp:
<h2>Add Post</h2>
...
<?= $this->element('posts/form') ?>
admin_edit.ctp:
<h2>Edit Post</h2>
...
<?= $this->element('posts/form') ?>
elements/posts/form.ctp:
switch ($this->params['action'])
{
case 'admin_edit':
echo $form->create('Post', array('action' => 'edit', 'admin' =>
1));
echo $form->hidden('Post.id');
break;
case 'admin_add':
default:
echo $form->create('Post', array('action' => 'add', 'admin' =>
1));
}
...
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en