For clarity - I got some of this a bit wrong - here's a better slice of code:

function beforeSave() {
        $this->data['Campaign']['slug'] = 
Inflector::slug($this->data['User']['first_name'] . ' ' . 
$this->data['User']['last_name']);
}

Jeremy Burns
Class Outfit

[email protected]
(t) +44 (0) 208 123 3822
(m) +44 (0) 7973 481949
Skype: jeremy_burns
http://www.classoutfit.com

On 19 Apr 2011, at 12:42, Jeremy Burns | Class Outfit wrote:

> If you only want to do this on a single model, you could forget the 
> behaviour. Just do something like this in your Campaign model:
> 
> function beforeSave() {
>       $this->data['Campaign']['slug'] = 
> Inflector::slug($data['User']['first_name'] . ' ' . 
> $data['User']['last_name']);
> }
> 
> That's obviously a very slim piece of (untested) code that isn't doing any 
> checks and assumes that you have populated the $data['User'] array key, but 
> it ought to work with a bit of tweaking.
> 
> Jeremy Burns
> Class Outfit
> 
> [email protected]
> (t) +44 (0) 208 123 3822
> (m) +44 (0) 7973 481949
> Skype: jeremy_burns
> http://www.classoutfit.com
> 
> On 19 Apr 2011, at 12:31, barricades wrote:
> 
>> Hey Jeremy, thanks for the advice. I'm a little bit new to all this
>> though. I have looked through the code before I posted but I'm
>> buggered if I can figure out exactly whats happening in there. I don't
>> suppose you (or anyone else who feels like chipping in) could give a
>> little more detail
>> 
>> 
>> 
>> On Apr 19, 12:19 pm, Jeremy Burns | Class Outfit
>> <[email protected]> wrote:
>>> There is nothing magic about the sluggable behaviour; it just populates the 
>>> slug field of the $this->data array on beforeSave() using Inflector. You 
>>> could write your own version. I have made some amendments to it myself for 
>>> a particular scenario - just step through the code and you'll see it's 
>>> fairly intuitive.
>>> 
>>> Jeremy Burns
>>> Class Outfit
>>> 
>>> [email protected]http://www.classoutfit.com
>>> 
>>> On 19 Apr 2011, at 12:14, barricades wrote:
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>>> I have a Campaign model and I want to create a slug for each new
>>>> campaign. I can do this easily with sluggable behaviour which is
>>>> awesome but I'd like the slug to be created from the first_name and
>>>> last_name field in the users table.
>>> 
>>>> How can I do this? I've seen it asked a couple of times online but
>>>> never answered. Surely it's possible!?!
>>> 
>>>> --
>>>> Our newest site for the community: CakePHP Video 
>>>> Tutorialshttp://tv.cakephp.org
>>>> Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help 
>>>> others with their CakePHP related questions.
>>> 
>>>> To unsubscribe from this group, send email to
>>>> [email protected] For more options, visit this group 
>>>> athttp://groups.google.com/group/cake-php
>> 
>> -- 
>> 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
> 
> -- 
> 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

-- 
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