Implement Query Sql In Yii

I have read a function in model

public function getData(){






    return $data;

How to transfer this value to controller and view????. I need help…pleasee

Simply call this method from your controller or view file by creating instance of your model class.Like

$dataResult = Modelname::model()->getData(); 


$model = new ModelName();

$dataResult =$model->getData(); 

Also if you are writing this code in controller action then you need to pass this data into render method’s array to get this info in view file.


So, in view file you can access that data with $data variable.

Also in each view file you have a property $model which refer to your model class, so you can use it as below:


how to print the value???. I`ve try to use "echo" but "Object of class CDbDataReader could not be converted to string"


you can use CDbCriteria

public function getData(){

                $criteria = new CDbCriteria;

		$criteria->select = 'data_student';


		$data    =  ModelName::model()->find($criteria);

		return $data;


and call this function on model

$model = new ModelName();

$data =$model->getData(); 


Note : if you want to fetch all record you want to add findAll condition

i think it’s works…

could you please show me your code?

Since if you are returning data from your method which is a Model class object. So, if you want to access any particular attribute from that then you should access it like.

echo $data->year;

echo $data->name; 

i hope you got my point.

I`ve got it… it has been solved… thanks

great ;)