如何在View Yii中获取查询bulider的结果?

时间:2017-08-15 01:29:02

标签: php view yii

我有这样的行动:

public function actionUpdate_daily($id) {
    $model = new Timesheet('searchbyvoyage');
    $model->unsetAttributes();  // clear any default values
    if (isset($_GET['Timesheet']))
        $model->attributes = $_GET['Timesheet'];

    $modelvoyage = $this->loadModelvoyage($id);
    //$vo = $this->loadVo($id, $id_voyage_order);

    $command = Yii::app()->db->createCommand(
                    "SELECT a.id_timesheet, a.id_voyage_order, COALESCE(b.duration,0) duration FROM timesheet a LEFT JOIN  
                    ( SELECT x.* 
                             , MAX(y.id_timesheet) previous
                         FROM timesheet X 
                         JOIN timesheet Y 
                           ON y.id_voyage_order = x.id_voyage_order 
                          AND y.id_timesheet < x.id_timesheet 
                        GROUP 
                           BY x.id_timesheet
                     ) b
                    ON b.previous = a.id_timesheet
                 WHERE a.id_voyage_order =".$id)
                ->queryAll(); ///        var_dump($command);  //       die();

 //   Yii::app()->params['MyVar'] = $command;


    $this->render('update_daily', array(
        'model' => $model,
        'modelvoyage' => $modelvoyage,
        'command' => $command
    ));
}

然后我想在View文件update_daily.php中使用widget持久显示查询结果:

   $this->widget('bootstrap.widgets.TbGridView', array(
 'columns' => array(
                    'name'=> 'Duration',
                    'value'=> $command,
                ),

但是,它没有工作和错误。

1 个答案:

答案 0 :(得分:0)

您可以参考此link来打印并检查您的查询是否是最新的

也可以使用

print_R($command);die();

在渲染上方检查查询结果返回