Model->model()->find yields a recordset


I am doing this

$model = Trips::model()->find(‘ID=:ID and destdatetime is null ‘, array(’:ID’=>$_POST[‘id’]));

There is only one row in the table, but still i am getting back a recordset instead of a row.

If i attempt this

$model->destdatetime = $_POST[‘destdatetime’]

it complains, Undefined index: destdatetime

so i have to do a foreach on $model to get the row.

But is it not so that only if you use findAll, it will return recordset.

and with a find it will return just a record.

Can anybody please help.



That means there is no key defined as ‘destdatetime’ into your $_POST var.

If you use inputs like

<input name="foobar[title]" type="text">

Then you ll have to get its value using :

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

echo $model->title;

Thank you so much. I guess, i should gone to sleep instead of sitting up till 4.00am.

now i see it all. such a small overlook.

Also i found that I was not creating a form like this

<?php echo CHtml::beginForm(); ?>

So, when i would click on the link button, on the command and the value was getting passed.

now after i put in the form attribute, everything works perfectly.

thanks once again.