Another thing, the actsAs array is only queried when the behavior
collection is created. Changing it won't (AFAIK) affect the already-
created behavior. Not 100% sure of the official method of configuring
at runtime.

How about overriding the save method directly?

class Photo extends AppModel {
  function save($data = null, $validate = true, $fieldList = array())
{
    $this->Behaviors->Upload->settings[$this->alias]['src']['dir'] =
'/' . $this->getEventSlug($this->data['Photo']['event_id']);
    return parent::save($data, $validate, $fieldList);
  }
}

(Note that depending on the behavior you use, you might need to use
$this->name instead of $this->alias - check how the config is keyed in
the behavior setup method)

On Apr 2, 1:35 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Another way to do it is to write a behaviour which does the alteration
> and include that in the actsAs array before the upload behaviour. They
> are run in order, so the upload behaviour will see what your behaviour
> did. That way you don't need to mess with the 3rd party code.
>
> Simonhttp://www.simonellistonball.com/
>
> On Apr 2, 1:30 pm, "Sam Sherlock" <[EMAIL PROTECTED]> wrote:
>
> > yep just seen that.  Guess that means no then can't be done.
>
> > Unless customise the behaviour.
>
> > I guess there is a reason for behaviors beforeSave being called before the
> > models beforeSave
>
> > On 02/04/2008, grigri <[EMAIL PROTECTED]> wrote:
>
> > > Behavior beforeSave() callbacks are called before the Model's
> > > beforeSave() callback.
>
> > > On Apr 2, 12:43 pm, "Sam Sherlock" <[EMAIL PROTECTED]> wrote:
> > > > I have and Event Model that hasMany Photos
>
> > > > I am using an upload behaviour and wish to save photos in a directory by
> > > the
> > > > event Slug
>
> > > > the below code is in the photo model the actsAs infor is updated but the
> > > new
> > > > information is ignored
>
> > > >     function beforeSave() {
> > > >         $this->actsAs['Upload']['src']['dir'].= '/' .
> > > > $this->getEventSlug($this->data['Photo']['event_id']);
> > > >         return true;
> > > >     }
>
> > > > how can I get this to work?
>
> > > > - S
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to