Problem Saving Object

Hi all,

I need to save records in the database from an asyncronous request. So I wrote this piece of code:




        parse_str($_POST['form'], $form);


        $id = $_POST['id'];

        $test = Test::model()->findByPk($id);

        if($test === null)

            throw new CHttpException(404, 'Test not found');

        print_r($test);

        $test->attributes = $form['Test'];


        if(isset($form['HoseConfiguration']))

        {

            $r = true;

            foreach($form['HoseConfiguration'] as $k=>$h)

            {

              $hose = $test->hoses[$k];

              $hose->attributes = $h;

              $s = $hose->save();

            }

        }

        if (!$test->save())

            echo 'error';

        else

            echo 'ok';



I did put the print_r in order to debug, because the record is not saved in the db, but actually it does return ‘ok’, and on the next call I can see the modified values inside the object properties.

Any explanation?

thanks a lot

Hi if you want to store the Test model

like




$test= new Test();

$test->setAttibutes($_POST['Test']);

$test->save(false);

giorg,

Mostly, you did not pass validation check when you save "Test" attributes. Using save(false) will not do the validation check.

See http://www.yiiframework.com/doc/guide/1.1/en/form.model