Barricades,
You don't really say WHERE the process seems to break down. The find
after the save seems suspicious to me. Is that returning the proper
slug to pass along to your view function? It looks like $slug will end
up holding the returned data array rather than the returned string
from the slug field (see below for more info)
You might take advantage of the fact that the id property of the model
is set to the id of the record that was created by save. So you should
be able to set your slug value properly after:
$this->Campaign->findById($this->Campaign-
>id,,array('fields'=>'slug'));
But you should also be aware that this will not return the slug field
directly. It's going to be in the usual data array:
Array
(
[Campaign] => Array
(
[slug] => My_crazy_slug
)
)
Regards,
Don
On May 7, 9:22 am, barricades <[email protected]> wrote:
> Hi, I'm new so please don't shout at me for the stupid question but...
>
> When I save a record I want to redirect straight to the record I just
> created. The record which I have just created uses sluggable behaviour
> to create a slug in a beforeSave, so I can't just use
> $this->data['Campaign]['slug'] as it doesn't exist before I save my
>
> campaign.
>
> in my add function I've got:
>
> <pre>
> if ($this->Campaign->save($this->data)) {
> $slug = $this->Campaign->find('first', array('fields' =>
> 'Campaign.slug'));
> $this->redirect(array('action' => 'view', $slug));
> } else {
> $this->Session->setFlash(__('The campaign could not be saved. Please,
> try again.', true));}
>
> </pre>
>
> and then
>
> <pre>
> function view($slug) {
> $campaign = $this->Campaign->find('first',
> array('conditions'=>array('Campaign.slug'=>$slug), 'recursive'=>-1));
> $this->set(compact('campaign'));
> }
> </pre>
>
> but that ain't working. I've tried a couple of other ways but I'm a
> bit stumped.
>
> How do I get the value that's in the slug column for the Campaign
> which has just been saved and pass it on to the view function so that
> I can display the right Campaign?
>
> thanks in advance :)
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php