No model/validation errors but save() return false...

As the topic when i call $model->save() the method return FALSE even if there aren’t validation errors. How can it be possible?

the error may be in a field that is not displayed?

try this after $model->save()

print_r($model->getErrors());

or

in the config/main.php

enable logs for error and trace

and see the file runtime/application.log




.....

    // application components

    'components'=>array(

        'log'=>array(

            'class'=>'CLogRouter',

            'routes'=>array(

                array(

                    'class'=>'CFileLogRoute',

                                        'levels'=>'error, trace',

                ),

            ),

        ),

.....



1 Like

You are probably using an event in your model that doesn’t return true. eg. public function beforeSave() {… return true;//must return true after everything}

Hi - I’m having the same issue as the original poster. I’ve figured out how to print out the errors, however, I still don’t see the errors in my application log. I’m wondering why that is. Here you say to configure the CFileLogRoute levels to display the ‘error’ and ‘trace’ levels. However, the docs state that, if you do not explicitly set the levels in the log configuration, it defaults to an empty string which means “all levels”. I have my route configured thusly:




...

'log'=>array(

    'class'=>'CLogRouter',

        'routes'=>array(

            array(

                // Write to the logfile in the 'runtime' directory

                'class'=>'CFileLogRoute'

                // Do not specify levels or categories in order to capture all

            )

        )

    )

)



…so again, why no validation errors in the app log? It’s worth noting that I do see plenty of other logging output in the log.

Any ideas?

Thanks

Validation error !== Application error.

Validation erros will not appear in your logfile. If you want that, you could e.g. attach a handler to onAfterValidate and log the model errors there. Would also be a nice exercise for creating a behavior… ;)

Thanks very much Mike, I will give that a try!

thanks - that worked for me

Thank you very much. It worked for me as well.

BR,

Yohan

I had the same issue. In my case I had overloaded the save() method and never returned the parent function. Ouch.




	public function save($runValidation = true, $attributes = null,$skipCoding=false) {

//Do Stuff

		return parent::save($runValidation, $attributes);

	}



took me way too long to see the missing return.

Hi, thanks for the tip, I was looking for it for hours!

Thanks, you saved my day :)

Somehow this needs to be mentioned in the documentation so it would be clear that this is required.

:) :rolleyes:

That helped me allot. THX!

Similar also happened to me, In my case i learned that you cannot create a method or function in the same name of your Model, even in small caps.




Class Reservations{

 public function reservations(){

    

 }

}




changed it to


public function reservationsList(){}




That worked for me too!

Thanks!! :)

I am getting strange issue.

Below is working


$model->getErrors()

Below not returning any errors.


$model->errors

Can anybody let me know what is the issue?

I found the solution. If you have overridden the $errors properly in your model then it not worked.