Yii CModel クラスを作成しようとしているので、フィルター処理され、並べ替えられたグリッドでデータを表示できます。
複雑すぎてはいけませんが、これをどうやって行うかは一生わかりません。それを実行する方法の段階的な指示セットを探していますが、何も見つかりません。:(
データベースのバックエンドを使いたくないので、CModel を拡張しています。
以下にコードをいくつか入れましたが、次に何をすべきかわかりません。実際のデータはどこに行くのですか?それは配列か何かに入らなければなりませんか?
どんな助けでも素晴らしいでしょう。
役立つ場合は、以下にコードをいくつか入れました。これが私のモデルです:
class MyModel extends CModel{
public $id,
$attribute1,
$attribute2,
$attribute3;
public function search(){
$criteria = new CDbCriteria;
$criteria->compare('id', $this->id);
$criteria->compare('attribute1', $this->attribute1);
$criteria->compare('attribute2', $this->attribute2);
$criteria->compare('attribute3', $this->attribute3);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
}
public function attributeNames(){
return array(
'id',
'attribute1',
'attribute2',
'attribute3',
);
}
}
これが私のコントローラーです:
class MyController extends CController{
public function actionIndex() {
$model = new MyModel('search');
$model->unsetAttributes();
if (isset($_GET['MyModel'])){
$model->setAttributes($_GET['MyModel']);
}
$this->render('index', array(
'model' => $model,
));
}
そして、これが私の見解です:
$this->widget('bootstrap.widgets.TbGridView', array(
'type'=>'striped bordered condensed',
'dataProvider'=>$model->search(),
'filter' => $model(),
'columns'=>array(
'id',
'attribute1',
'attribute2',
'attribute3',
)
));