Yii Framework Forum: How to get model data like array - Yii Framework Forum

Jump to content

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

How to get model data like array Rate Topic: -----

#1 User is offline   holala 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 74
  • Joined: 23-December 09

Posted 05 March 2010 - 09:26 AM

$criteria=new CDbCriteria;
$criteria->select='connect_to';
$criteria->condition='employee_id=:employeeID AND group_id=:groupID AND lev=:lev';
		$criteria->params=array(':employeeID'=>$employeeID,':groupID'=>$groupID,':lev'=>$lev);
return self::model()->findAll($criteria);

method findAll return a object array,dose it has a way can make object array to normal array just like $data[0]=1;$data[1]=2;

Thanks!
0

#2 User is offline   jsoo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 01-March 10
  • Location:Durham, NC, USA

Posted 05 March 2010 - 09:51 AM

CActiveRecord implements (via CModel) ArrayAccess, so if $data is the result of findAll() the following two lines are equivalent:

echo $data[0]->employee_id;
echo $data[0]['employee_id'];


Is that what you mean?
0

#3 User is offline   rohit 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 71
  • Joined: 08-July 09
  • Location:India

Posted 05 March 2010 - 10:04 AM

$obj=self::model()->findAll($criteria);
$arr=$obj->attributes;


model() method returns Returns the static model of the specified CActiveRecord class.
Check CActiveRecord properties.. "attributes"
-1

#4 User is offline   szako 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 56
  • Joined: 17-May 10

Posted 22 December 2010 - 08:11 AM

View Postholala, on 05 March 2010 - 09:26 AM, said:

$criteria=new CDbCriteria;
$criteria->select='connect_to';
$criteria->condition='employee_id=:employeeID AND group_id=:groupID AND lev=:lev';
		$criteria->params=array(':employeeID'=>$employeeID,':groupID'=>$groupID,':lev'=>$lev);
return self::model()->findAll($criteria);

method findAll return a object array,dose it has a way can make object array to normal array just like $data[0]=1;$data[1]=2;

Thanks!


Solved here and here.
-------------
m(o_O)m
0

#5 User is offline   Dhara 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 48
  • Joined: 26-April 14
  • Location:Ahmedabad, India

Posted 11 December 2014 - 12:16 AM

Here is my problem in rights module.

$data = array();
$sql = "SELECT * FROM authitem WHERE created_by =".Yii::app()->user->id;
$dbCommand = Yii::app()->db->createCommand($sql);
$data = $dbCommand->queryAll();

This gives me normal array but i want model array of authitem. is there any solution?
0

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