On 4/22/07, Dr. Tarique Sani <[EMAIL PROTECTED]> wrote:
>
>
> This happens because Controller::render does not pass
> $this->validationErrors to the View but jumps through several hoops
> passing $this->{$modelname}->validationErrors to the View instead.
>
> I was supposed to write a test to demo this flaw but sorry never got
> around to it. The following thread is the related one
>
>
> http://groups.google.com/group/cake-php/browse_thread/thread/d55cb26bd1c1833a/feee28ce352f5260?lnk=gst&q=Controller%3A%3Arender&rnum=1&hl=en#feee28ce352f5260
Hi Tarique,
I had a look at your solution in the above post and it doesn't work for me,
at least in 1.1.x. From what I can see in Controller::render the code that
sets the validationErrors in the views is:
function render($action = null, $layout = null, $file = null) {
$viewClass = $this->view;
if ($this->view != 'View') {
$viewClass = $this->view . 'View';
loadView($this->view);
}
$this->beforeRender();
$this->__viewClass =& new $viewClass($this);
if (!empty($this->modelNames)) {
foreach($this->modelNames as $model) {
if
(!empty($this->{$model}->validationErrors)) {
$this->__viewClass->validationErrors[$model] =
&$this->{$model}->validationErrors;
}
}
}
$this->autoRender = false;
return $this->__viewClass->render($action, $layout, $file);
}
The problem is that this will only work for first level models (ie. whatever
is in $this->modelNames). If, as it is in my case, you have any associated
models to any of $this->modelNames, it will not fill the validationErrors
array. I started modifying this function in my app_controller.php class and
didn't quite get it right, but it got a lot further than it is now.
I'm not sure how no-one has ran into this problem yet. I, for example, have
a form with some fields from one of the models in $this->modelNames and some
other fields from models associated to the models in $this->modelNames.
What I did was a foreach inside the foreach above and used
$this->{$model}->modelToTables (from memory) to go through all the models
and get the errors for each one and add to
$this->__viewClass->validationErrors. The problem is that it got a bit messy
after I tried to go into 2nd and 3rd level.
Am I doing something wrong? Normally when I see a problem this big I start
to think I'm doing something wrong, otherwise I've no idea how nobody has
ran into it. Perhaps I'm the only twisted one trying to do it this way?
Thanks in advance for any feedback on the above.
Cheers,
Gonzalo
> Cheers
> Tarique
>
>
> On 4/22/07, Mariano Iglesias <[EMAIL PROTECTED]> wrote:
> >
> > Can you create a ticket for this?
> >
> > https://trac.cakephp.org
> >
> > Don't forget to mention your Cake version number on the appropriate
> field.
> >
> > Also if it's not too much effort create another ticket mentioning the
> error
> > you got when you tried using dot notation.
> >
> > Thanks!
> >
> > -MI
> >
> >
> ---------------------------------------------------------------------------
> >
> > Remember, smart coders answer ten questions for every question they ask.
> > So be smart, be cool, and share your knowledge.
> >
> > BAKE ON!
> >
> > blog: http://www.MarianoIglesias.com.ar
> > ________________________________________
> > De: [email protected] [mailto:[EMAIL PROTECTED] En
> nombre
> > de Gonzalo Servat
> > Enviado el: Domingo, 22 de Abril de 2007 01:09 a.m.
> > Para: [email protected]
> > Asunto: Re: Validation of a related Model
> >
> > Forgot to mention that this didn't work (just didn't output anything,
> > similar to if I had left it as 'Member/field').
> >
> >
> > >
> >
>
>
> --
> =============================================================
> PHP for E-Biz: http://sanisoft.com
> Cheesecake-Photoblog needs you!: http://cheesecake-photoblog.org
> =============================================================
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---