Sunday, January 25, 2009

behavior settings and view

I have some settings in a Behavior which I'll need exposed in the
view. I haven't been able to come up with a good solution for this and
so now I'm wondering if my entire approach is flawed.

I'm working on a MediaBehavior. This class contains a few generic
methods and is extended by MediaImageBehavior, MediaVideoBehavior,
etc., which are the classes in the model's $actsAs array. I chose to
go this route because I have a situation where users can upload one of
several different types of file, each of which requires different
handling (though there are a few common needs, handled by the parent
behavior).

These Behaviors' each have an $alias (eg. 'Image') and the beforeSave
methods looo like:

if ($Model->data['MediaType']['name'] == $this->alias)
{
...
}
return true;

I don't yet know if this approach is going to work. If anyone sees any
gotchas, please do speak up. Meanwhile the point of this post:

Each of these behaviors has some default settings. For Image, it's
max_width, max_height, max_file_size, etc. In my views, I need to be
able to specify these values; most importantly, for the form's hidden
MAX_FILE_SIZE element. But I can't figure out how to best get at these
values. I could grab them from the model's behaviors in the controller
action:.

$this->set('max_file_size',
$this->Model->Behaviors->MediaImageBehavior->settings['Model']['max_file_size']);

That seems awfully hacky. I'd need to have a switch to query the
particular behavior settings based upon $data['MediaType']['name'].

Anyone see a better way to handle this?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: