[Solved] Saving model fails to write into database

In my actionCreate():


$model=new Search;


    if(isset($_POST['Search']))

    {

        $model->attributes=$_POST['Search'];

        $model->save();

    }

It doesn’t save anything into the database. The $model->save() returns with true, no error message when I try using getErrors(), also $model->validate() returns with true when I try to use it and $model->save(false) is the same output.

I have the following in the model’s rules:


array('user_id, session_id, testcase_id, exec', 'safe', 'on'=>'search')

I also printed the $model->attributes after sending the form and it has the right values. The database table accepts the given values, I don’t get SQL error when adding the values manually.

Thanks in advance for your help.

Can you paste the result of $model->attributes before $model->save() ?


Array ( [user_id] => testid [session_id] => testsession [testcase_id] => testcase [exec] => exec )



(yes, user_id is a string, and the others too)

stackoverflow.com/a/33761428/4916039

As I mentioned I already tried the $model->save(false). And I don’t even have duplicated variables.

You can read also this http://www.yiiframework.com/wiki/161/understanding-safe-validation-rules/

Can you try $model=new Search(‘search’);?

Useful article, thanks, but I still don’t know how it could help me in this case. Maybe I’m just dumb, tried to play around the safe attributes a bit but the problem still occurs.

I just tried it but same result :(

Finally solved. The problem was that I named the model "search" and somehow it might have encountered with the search function. As I renamed it to "user_search" it immediatelly worked properly. Thanks for your help tho.