On Mon, May 18, 2009 at 10:22 PM, Jorge Garifuna <[email protected]> wrote:
>
> I'm creating an application with the following two tables:
>
> posts:
> - id
> - title
> - body
>
> comments:
> - id
> - post_id
> - comment
>
> I was able to bake this app and all the links are working. Now I would
> like to customize the app so that, when a comment is added from the
> post:
>
> - the post id (list) is not showing in the comment view
Just delete it from your view. Bake creates very generic views and,
unless you change the templates, you'll generally need to clean them
up somewhat.
> - the post id gets saved when the comment is saved
$form->hidden('Comment.post_id')
Depending on how you're doing things, you may need to do:
$form->hidden('Comment.post_id', array('value' => $post_id))
... that's if you've set the $post_id var.
> - the comment gets redirected to the post the comment originated from
> after saving
$this->redirect(
array(
'controller' => 'Post',
'action' => 'view',
$post_id
)
);
Or, if you don't want the 'view' part in the URL, you might want
something like this:
$this->redirect(
array(
'controller' => 'Post',
'action' => 'view',
'id' => $post_id
)
);
In which case your route would be:
Router::connect(
'/posts/:id',
array('controller' => 'posts', 'action' => 'view'),
array('id' => '[0-9]+', 'pass' => array('id'))
);
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---