Work with DB

Hi all,

How can I work with DB like make a connection, command, execute and bind it to grid ?

What file should I create ? is it in AR model, or another model file ?


Please read first the Definitive Guide to Yii -

there is a section - Working with Databases -

thanks mdomba,

actually, I want to bind data to detailview at view, which the data is customize by me.

here is my code at view :

<?php $this->widget('zii.widgets.CDetailView', array(











)); ?>

and this is the code at model :

public function dataCustom($id)


		$connection = Yii::app()->db;

		$sql = "select as id,a.task_name as task_name,a.user_name as user_name,a.time_start as time_start,a.time_end as time_end ,c.status_name as status_name,b.group_task as group_task from timekerja a inner join group_task b on a.group_task = inner join status_task c on a.status_task = c.status_id where$id";

		$command = $connection->createCommand($sql);

		$result = $command->query();

		return $result;


the result of dataCustom($id) should bind to the detail view.

how can I do that ?

this is the error I got : Property "" is not defined.

anyone can help answer ?