Controller, Model, View and Helper all have a class variable called
'validationErrors';

When Model::invalidFields() is called (e.g. from Model::save()), the
model's $validationErrors is set.
This array is field-keyed, like `array( 'title' => ..., 'description'
=> ...)

When the controller goes to render, it constructs the view and then
(for each model it knows) passes that model's
$validationErrors to the View in a modelname-keyed array, so $View-
>validationErrors looks like

array(
  'Ham' => array('title' => ..., 'description' => ...),
  'Eggs' => array('foo' => ..., 'bar' => ...)
)

Then the View passes this array on to each of the helpers it loads.

So, from within the Behavior, the only object you have access to is
the parent model. You cannot directly influence the view (it doesn't
exist yet) or the controller (that would be terrible MVC).

Your best bet would be to set the model's validationErrors array, with
a prefixed key (like $Model->invalidate('attachment_' . $fieldName,
'...'). This will then get propagated to the view and then the
helpers.

You'd then be able to access this directly in the view by using $form-
>error('Model.attachment_whatever');



On Jan 25, 12:14 pm, GreyCells <[EMAIL PROTECTED]> wrote:
> I have a model that has a behavior.
>
> e.g. Post var $actsAs = array('Attachment');
>
> When the Post model is saved, the behaviour->beforeSave callback is
> fired to save or update the Attachment model.
>
> My question is: How do I cleanly propagate any errors raised by the
> Attachment model back to the View/form? I know I need to populate the
> View->validationErrors, but I don't want to interfere with the
> automagic error handling of the primary model.
>
> ~GreyCells
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
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