Saturday, October 8, 2011

Re: checking if Save() method was successful...

Your model's save method doesn't actually return a boolean, you can
just use the method call itself in a conditional, but it actually
returns an array. You could check if $updated is not empty I believe:

if (!empty($updated)) {

}

Or use the method call itself in a condition to see if the save was
successful:

if ($this->Report->save($updates)) {

}

On Oct 8, 8:30 am, Tomfox Wiranata <tomfox.wiran...@gmail.com> wrote:
> hi,
>
> i have a simple save()
>
> $updates['Report']['status']= $new_status;
> $updated = $this->Report->save($updates);
>
> now i want to check, if the saving was successful and echo the result:
>
> if ($updated)
>                 {
>                                 $this->set('success', "ok");
>                                 $this->render('../elements/admin/success', 'ajax');
>                 }
>                 else
>                 {
>
>                         $this->set('success', "err");
>                         $this->render('../elements/admin/success', 'ajax');
>                 }
>
> so even if i change the field "status" to "doesntexist", which makes
> the saving a fail,  i dont get the "err" as a callback.
> so i thought i should debug $updated to see what callback i get:
>
> Array
> (
>     [Report] => Array
>         (
>             [fk_post_id] => 205
>             [fk_user_id] => 74
>             [reason] => test
>             [description] => test
>             [created] => 2011-10-07 22:15:21
>             [id] => 44
>             [fk_reporting_user_id] => 74
>             [status] => pending
>         )
> more data ...
>
> so $updated returns an array. i was expecting "true" or "false" ??? so
> confusing..
>
> what do i need to change?
>
> thanks sooo much ;)

--
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
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate