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:未設定
これを整理するのを手伝ってください。
前もって感謝します!