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

Reply via email to