Yii Framework Forum: Help with Call to undefined method stdClass::save() message - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Help with Call to undefined method stdClass::save() message Rate Topic: -----

#1 User is offline   MadSkillsTisdale 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 101
  • Joined: 15-February 09
  • Location:New Orleans, LA

Posted 31 March 2009 - 10:55 PM

So, I'm getting this problem:

Call to undefined method stdClass::save()in /Users/corey/Sites/RTS/protected/controllers/SampleController.php on line 471


$criteria=new CDbCriteria;
$criteria->condition='"sampleId"=:sampleId AND "sampleMeasurementTypeId"=:sampleMeasurementTypeId AND "sourceLabId"=:sourceLabId';
$criteria->params=array(
':sampleId'=>$postSample['id'],
':sampleMeasurementTypeId'=>2,
':sourceLabId'=>3,
);
$srm=sampleRequiredMeasurement::model()->find($criteria);
$srm->attributes['sampleId'] = $postSample['id'];
$srm->attributes['sampleMeasurementTypeId'] = 2;
$srm->attributes['sourceLabId'] = 3;
$srm->save();
unset($srm);


sampleMeasurementTypeId has 4 columns, id, sampleId, sampleMeasurementTypeId, sourceLabId.

Id is a serial column and the other three are integers. If I do not use the criteria and just do

$srm=sampleRequiredMeasurement::model()->find();

I get a table row just fine. If I do

$srm=sampleRequiredMeasurement::model()->find($criteria); 

and do a var_dump on it immediately afterwards, it is NULL.

What am I doing wrong?
0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,905
  • Joined: 04-October 08
  • Location:DC, USA

Posted 01 April 2009 - 05:56 AM

What is line 471?
0

#3 User is offline   MadSkillsTisdale 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 101
  • Joined: 15-February 09
  • Location:New Orleans, LA

Posted 01 April 2009 - 10:54 AM

$srm->save();

However, I suspect this is a product of me programming way past my bed time. The solution is pretty obivous, just the error message was wierd. I forgot to do a check against the find to see if it returned results and create a new object if find found nothing.

I am now accepting insults to my intelligence :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users