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 ?
Thanks,
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 ?
Thanks,
Please read first the Definitive Guide to Yii - http://www.yiiframework.com/doc/guide/
there is a section - Working with Databases - http://www.yiiframework.com/doc/guide/database.overview
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(
'data'=>$model->dataCustom($model->id),
'attributes'=>array(
'id',
'group_task',
'task_name',
'user_name',
'time_start',
'time_end',
'status_task',
),
)); ?>
and this is the code at model :
public function dataCustom($id)
{
$connection = Yii::app()->db;
$sql = "select a.id 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 = b.id inner join status_task c on a.status_task = c.status_id where a.id=$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 "CDbDataReader.id" is not defined.
anyone can help answer ?
thanks