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

2011-10-11 Thread WebbedIT
Eh? Am I being daft here, doesn't save() return true or false if the
save succeeds or fails regardless of the failure reason?

I have never had a save fail and my success logic run!

I only ever use:

if($this->ModelName->saveAll($this->data)) {
  // success logic
} else {
  // fail logic
}

Confused and bemused, Paul

On Oct 10, 10:38 am, "flo.kl...@googlemail.com"
 wrote:
> You should use is_array and is_empty to check your return value. Also i would 
> recommend to pass your return value to the view and look at it with 
> debug($updated);
>
> -flosky
>
> Tomfox Wiranata  schrieb:
>
> thanks for all the answers.
> i want to achieve this:
>
> whenever the save() process failed, not matter what the reason was (db
> connection, missing field in db, code error etc. etc.), I need to
> know!
>
> so i created a test case with a fake field that does not exist in my
> table, so i make sure that save() fails:
>
> $updates['Report']['fictionalField']= $new_status;
>
> now the data is not saved and i still get an unempty array returned!!
> and so my check
>
> updated = $this->Report->save($updates);
>
> if ($updated)
> {}
>
> returns true and i would think the saving worked.
>
> somehow i cannot catch that error!
>
> On Oct 10, 8:58 am, WebbedIT  wrote:
>
>
>
>
>
>
>
>
>
> > Model::save returns true or false and if it returns false the error
> > array is available in the model and view as $this->ModelName-
>
> > >invalidFields() and $this->validationErrors respectively.
>
> > What are you trying to achieve that requires more than this?
>
> > HTH, Paul.
>
> > On Oct 9, 11:52 am, euromark  wrote:
>
> > > i cant follow you
> > > wants your problem?
>
> > > if ($result) {}
> > > works as expected in your case
> > > NOT EMPTY ARRAY equals FALSE
>
> > > therefore you already have a valid check if the saving succeeded
>
> > > On 9 Okt., 11:48, Tomfox Wiranata  wrote:
>
> > > > hello andrewperk,
>
> > > > thanks for your help. i appreciate that. one question though:
>
> > > > what do i have to do to get a false?
> > > > because when i use made up database fields i still get a filled array
> > > > as a return. so in that case the saving failed and i still dont get a
> > > > false.
>
> > > > is there maybe another way to check if saving succeeded?
>
> > > > thanks  a lot!
>
> > > > On 9 Okt., 02:21, andrewperk  wrote:
>
> > > > > I may have said that wrong, I think it returns two different things,
> > > > > if successful it will return an array if not I believe it just returns
> > > > > false.
>
> > > > > On Oct 8, 4:58 pm, andrewperk  wrote:
>
> > > > > > 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  
> > > > > > 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 ;)- Hide quoted text -
>
> > - Show quoted text -
>
> --

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

2011-10-10 Thread flo.kl...@googlemail.com
You should use is_array and is_empty to check your return value. Also i would 
recommend to pass your return value to the view and look at it with 
debug($updated);

-flosky



Tomfox Wiranata  schrieb:

thanks for all the answers.
i want to achieve this:

whenever the save() process failed, not matter what the reason was (db
connection, missing field in db, code error etc. etc.), I need to
know!

so i created a test case with a fake field that does not exist in my
table, so i make sure that save() fails:

$updates['Report']['fictionalField']= $new_status;

now the data is not saved and i still get an unempty array returned!!
and so my check

updated = $this->Report->save($updates);

if ($updated)
{}

returns true and i would think the saving worked.

somehow i cannot catch that error!


On Oct 10, 8:58 am, WebbedIT  wrote:
> Model::save returns true or false and if it returns false the error
> array is available in the model and view as $this->ModelName-
>
> >invalidFields() and $this->validationErrors respectively.
>
> What are you trying to achieve that requires more than this?
>
> HTH, Paul.
>
> On Oct 9, 11:52 am, euromark  wrote:
>
>
>
> > i cant follow you
> > wants your problem?
>
> > if ($result) {}
> > works as expected in your case
> > NOT EMPTY ARRAY equals FALSE
>
> > therefore you already have a valid check if the saving succeeded
>
> > On 9 Okt., 11:48, Tomfox Wiranata  wrote:
>
> > > hello andrewperk,
>
> > > thanks for your help. i appreciate that. one question though:
>
> > > what do i have to do to get a false?
> > > because when i use made up database fields i still get a filled array
> > > as a return. so in that case the saving failed and i still dont get a
> > > false.
>
> > > is there maybe another way to check if saving succeeded?
>
> > > thanks  a lot!
>
> > > On 9 Okt., 02:21, andrewperk  wrote:
>
> > > > I may have said that wrong, I think it returns two different things,
> > > > if successful it will return an array if not I believe it just returns
> > > > false.
>
> > > > On Oct 8, 4:58 pm, andrewperk  wrote:
>
> > > > > 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  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 ;)- Hide quoted text -
>
> - Show quoted text -

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

-- 
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+unsubscr

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

2011-10-10 Thread Tomfox Wiranata
thanks for all the answers.
i want to achieve this:

whenever the save() process failed, not matter what the reason was (db
connection, missing field in db, code error etc. etc.), I need to
know!

so i created a test case with a fake field that does not exist in my
table, so i make sure that save() fails:

$updates['Report']['fictionalField']= $new_status;

now the data is not saved and i still get an unempty array returned!!
and so my check

updated = $this->Report->save($updates);

if ($updated)
{}

returns true and i would think the saving worked.

somehow i cannot catch that error!


On Oct 10, 8:58 am, WebbedIT  wrote:
> Model::save returns true or false and if it returns false the error
> array is available in the model and view as $this->ModelName-
>
> >invalidFields() and $this->validationErrors respectively.
>
> What are you trying to achieve that requires more than this?
>
> HTH, Paul.
>
> On Oct 9, 11:52 am, euromark  wrote:
>
>
>
> > i cant follow you
> > wants your problem?
>
> > if ($result) {}
> > works as expected in your case
> > NOT EMPTY ARRAY equals FALSE
>
> > therefore you already have a valid check if the saving succeeded
>
> > On 9 Okt., 11:48, Tomfox Wiranata  wrote:
>
> > > hello andrewperk,
>
> > > thanks for your help. i appreciate that. one question though:
>
> > > what do i have to do to get a false?
> > > because when i use made up database fields i still get a filled array
> > > as a return. so in that case the saving failed and i still dont get a
> > > false.
>
> > > is there maybe another way to check if saving succeeded?
>
> > > thanks  a lot!
>
> > > On 9 Okt., 02:21, andrewperk  wrote:
>
> > > > I may have said that wrong, I think it returns two different things,
> > > > if successful it will return an array if not I believe it just returns
> > > > false.
>
> > > > On Oct 8, 4:58 pm, andrewperk  wrote:
>
> > > > > 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  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 ;)- Hide quoted text -
>
> - Show quoted text -

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


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

2011-10-10 Thread WebbedIT
Model::save returns true or false and if it returns false the error
array is available in the model and view as $this->ModelName-
>invalidFields() and $this->validationErrors respectively.

What are you trying to achieve that requires more than this?

HTH, Paul.

On Oct 9, 11:52 am, euromark  wrote:
> i cant follow you
> wants your problem?
>
> if ($result) {}
> works as expected in your case
> NOT EMPTY ARRAY equals FALSE
>
> therefore you already have a valid check if the saving succeeded
>
> On 9 Okt., 11:48, Tomfox Wiranata  wrote:
>
>
>
>
>
>
>
> > hello andrewperk,
>
> > thanks for your help. i appreciate that. one question though:
>
> > what do i have to do to get a false?
> > because when i use made up database fields i still get a filled array
> > as a return. so in that case the saving failed and i still dont get a
> > false.
>
> > is there maybe another way to check if saving succeeded?
>
> > thanks  a lot!
>
> > On 9 Okt., 02:21, andrewperk  wrote:
>
> > > I may have said that wrong, I think it returns two different things,
> > > if successful it will return an array if not I believe it just returns
> > > false.
>
> > > On Oct 8, 4:58 pm, andrewperk  wrote:
>
> > > > 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  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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


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

2011-10-09 Thread euromark
i cant follow you
wants your problem?

if ($result) {}
works as expected in your case
NOT EMPTY ARRAY equals FALSE

therefore you already have a valid check if the saving succeeded




On 9 Okt., 11:48, Tomfox Wiranata  wrote:
> hello andrewperk,
>
> thanks for your help. i appreciate that. one question though:
>
> what do i have to do to get a false?
> because when i use made up database fields i still get a filled array
> as a return. so in that case the saving failed and i still dont get a
> false.
>
> is there maybe another way to check if saving succeeded?
>
> thanks  a lot!
>
> On 9 Okt., 02:21, andrewperk  wrote:
>
>
>
>
>
>
>
> > I may have said that wrong, I think it returns two different things,
> > if successful it will return an array if not I believe it just returns
> > false.
>
> > On Oct 8, 4:58 pm, andrewperk  wrote:
>
> > > 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  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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


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

2011-10-09 Thread Tomfox Wiranata
hello andrewperk,

thanks for your help. i appreciate that. one question though:

what do i have to do to get a false?
because when i use made up database fields i still get a filled array
as a return. so in that case the saving failed and i still dont get a
false.

is there maybe another way to check if saving succeeded?

thanks  a lot!

On 9 Okt., 02:21, andrewperk  wrote:
> I may have said that wrong, I think it returns two different things,
> if successful it will return an array if not I believe it just returns
> false.
>
> On Oct 8, 4:58 pm, andrewperk  wrote:
>
>
>
>
>
>
>
> > 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  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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


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

2011-10-08 Thread andrewperk
I may have said that wrong, I think it returns two different things,
if successful it will return an array if not I believe it just returns
false.

On Oct 8, 4:58 pm, andrewperk  wrote:
> 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  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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


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

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


checking if Save() method was successful...

2011-10-08 Thread Tomfox Wiranata
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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php