here is the code.
Controller
for ($i=0; $i<$roundTimes; $i++)
$generateMath['e'][$i] = Equation::model()->generateMath($_POST['Equation']['code'], $offSetRe);
Model :: Equation :: generateMath
....switch.....
case $REVIEW_ALL:
$reequation = Reequation::model()->getUserReequation(0, $offSetRe);
// print_r($reequation->first);
$EF = $reequation->first;
$ES = $reequation->second;
$EO = $reequation->operator;
$id = $reequation->id;
break;
.....code switch.....
$arrMathElements =array('F'=>$EF , 'S'=>$ES, 'O'=>$EO, 'id'=>$id);
return $arrMathElements;
Model Reequation :: getUserReequation
/**
*
* Get a Reequation from DB
* @param int $type (1=>today || 0=>all)
* @param int $max the max rand value
* return 1 Reequation one times
*/
public function getUserReequation($type = 0, $max=0)
{
$criteria = new CDbCriteria();
$criteria->condition = ' uid = :uid and end_date is null ';
$criteria->params[':uid'] = Yii::app()->user->id;
if ($type == 1){
$criteria->condition .= ' and add_date > :today_date ';
$criteria->params[':today_date'] = date('Y-m-d');
}
$criteria->order = ' id DESC ';
$criteria->limit = 1;
$criteria->offset = rand(1, $max);
$reEquationResult = Reequation::model()->find($criteria);
// print_r($reEquationResult->uid);
// print_r($reEquationResult);
return $reEquationResult ;
}
Yii will tell me at "$EF = $reequation->first;" Trying to get property of non-object.
I did a lot of debug…
=========1
Controller
$generateMath['e'] = Equation::model()->generateMath($_POST['Equation']['code'], $offSetRe);
when I changed controller like this, it works fine. just remove loop why?
===========2
when keep loop and get error msg, I found used print_r($reEquationResult); in Model Reequation :: getUserReequation can get object and values from DB, but when I use print_r($reEquationResult->uid); the same error msg shows again.
who can tell me why?
thank you very much.