我正在尝试从 SQL Server 存储过程中获取数据,所以我在 YII 框架中使用 createCommand 方法。
我已经创建了 gridView 但在 CDetailView 中没有显示使用相同的东西。
我用了:
public function getHotel($id = 0){
        /**
         * Building Query for Getting Hotel List Stored Procedure with
         * or Without Parameter defined
         */
        $sql = "EXECUTE procName '".$id."'";
        /**
         * Set Database Connection and instruct Yii Query Builder to Execute SQL
         */
        $connection = Yii::app()->db;
        $command = $connection->createCommand($sql);
        /**
         * Execute the stored procedure.
         */
        $results = $command->queryAll();
        /**
         * Set the DataProvider that will be used in Grid
         */
        $sqlDataProvider = new CArrayDataProvider($results,array(
            'keyField'      => 'hotel_id',
        ));
        /**
         * Return DataProvider
         */
        return $sqlDataProvider;
    }
它正确地为我提供了所需的 id 数据的数组,但是当我在 view.php 中使用 CDetailView 时,什么都没有显示。
这是我的控制器代码:
public function actionView($id)
{
        /**
         * Call the method to generate the CArrayDataProvider by executing the stored procedure.
         */
        $dataProvider = Hotel::model()->getHotel($id);
        $model = new Hotel('getHotel('.$id.')');
        /**
         * Return with the webpage that contains the data grid using the $dataProvider
         * generated earlier
         */
        $this->render('view',array(
            'dataProvider'  => $dataProvider,
            'model'         => $model,
        ));
}
这是 view.php 代码:
<h1>View Hotel #<?php echo $model->hotel_id; ?></h1>
<?php $this->widget('zii.widgets.CDetailView', array(
    'data'=>$dataProvider,
    'attributes'=>array(
        'hotel_id',
        'name',
        'category_id',
        'currency_id',
        'facility',
        'rel_days',
        'city_id',
        'country_id',
        'telephone',
        'location',
        'email',
        'fax',
        'contact_person',
        'website',
        'address',
        'gl_id',
        'policy',
        'status',
        'date_added',
        'date_modified',
        'user_id',
    ),
)); ?>
我在浏览器上得到的输出是这样的:
酒店 ID : 未设置
名称:未设置
.
.
.
.
.
.
.
.
用户 ID:未设置
请帮我解决这个问题。
提前致谢!