i have a simple code that is supposed to keep track of history of last visited url in the database for a given model.
i have inserted the following code in the AR model :
public function manageHistory()
{
$user = Yii::app()->user->getId();
$history=History::model()->find('user_id=:userID', array(':userID'=>$user));
if (empty($history))
{ // no history so create the 1st visted record
$history = new History;
$history->user_id = $user;
$history->lesson_id = $this->lesson_id;
$history->save();
}
if (!empty($history))
{ //update the existing record with new record
$history->lesson_id = $this->lesson_id;
$history->save();
}
}
if (!empty($history))
{
foreach($history as $history_1){
//update the existing record with new record
$history_1->lesson_id = $this->lesson_id;
$history_1->save(false);
}
}
@Shahcheraghean - thanks for replying. the column names are correct, so that is not the issue.
@balu - thanks for replying. your suggestion is not working - in any case there is only one row for each user_id in the database. so foreach should not be of relevance. I nverehteless tried your suggestion but the error persists
What exactly is this statement meaning ?
"Column name must be either a string or an array."