Yii Framework Forum: Column Name Must Be Either A String Or An Array. - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Column Name Must Be Either A String Or An Array. Rate Topic: -----

#1 User is offline   sanguina 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 22-July 12

Posted 04 March 2013 - 01:25 AM

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();
		 }
		 
	}




This code gives me the following error:

Column name must be either a string or an array.

What does this mean ? :(

thanks
until I become certain that there is no certainty.
0

#2 User is offline   Shahcheraghean 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 478
  • Joined: 12-December 12
  • Location:Mashhad, IRAN

Posted 04 March 2013 - 03:10 AM

it seem`s that the problem is about your column name.
check them, maybe the column names you used here differ from the table or model names.
www.shgn.ir
www.shgn.ir/yii-framework/
yii2.swsco.ir
In a world without any fences or walls,Who needs Gates or Windows!
0

#3 User is offline   Balu 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 153
  • Joined: 09-August 11
  • Location:Kerala, India

Posted 04 March 2013 - 03:19 AM

View PostShahcheraghean, on 04 March 2013 - 03:10 AM, said:

it seem`s that the problem is about your column name.
check them, maybe the column names you used here differ from the table or model names.


Make like this
 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);
}
                 }


Hope this will work for you.
0

#4 User is offline   sanguina 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 22-July 12

Posted 04 March 2013 - 09:14 AM

Bumping this thread as i am still stuck :huh:

@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."

Any other suggestion would be really appreciated
until I become certain that there is no certainty.
0

#5 User is offline   sanguina 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 22-July 12

Posted 04 March 2013 - 09:21 AM

hey i got this solved, it just turns out that my tbl_history did not have a primary key.
i set it right and it works great now :)


does that imply that all databases must have a primary key for any active record access ?
until I become certain that there is no certainty.
1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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