0

次の機能を追加しようとしていますが、どこから始めればよいかわかりません。アドバイス、例、または指示をいただければ幸いです。

このコンテキストで、メイン モデルの cgridview にボタンを追加したいと考えています。このモデルの cgridview で利用可能な各レコードには、lot と呼ばれる固有の属性があります (例: R3XSEF9)

データベースには、同じロット属性を持つレコードを持つ別のセカンダリ テーブル/モデルがあります。ただし、このテーブルには、可能なすべてのレコードのうち特定のレコードしかなく、重複することもあり、さまざまな属性のセットがあります。

私がやりたいことは、ロット属性を使用して、たとえば cgridview のロット R3XSEF9 を使用して、セカンダリ テーブルを検索して、同じロット R3XSEF9 を含む 1 つ以上の対応する行があるかどうかを確認することです。

もしそうなら、ボタンを CButtonColumn に表示し、セカンダリ テーブルの対応するモデルのビューにリンクしたいと思います。そうでない場合は、ボタンを表示したくありません。

助けてくれてありがとう。明確化が必要な場合は、喜んで対応させていただきます。

4

1 に答える 1

1

まず、モデルクラスの「relations」関数を使用してテーブルをリンクする必要があります。すでに入力されているDBリレーションでFOREIGNKEY制約を使用する場合。

SQLステートメント:

CREATE TABLE Model1
(
    ...
    FOREIGN KEY(lot) REFERENCES MainModel(lot) ON UPDATE CASCADE ON DELETE RESTRICT,
    ...
)

モデルクラス:

 class MainModel extends CActiveRecord
 {
         ...

    public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'lots' => array(self::HAS_MANY, 'Model2', 'lot'),
        );
    }

次に、グリッド(ビューファイル)で次のようにカスタムボタン列を使用できます。

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'main-grid',
    'dataProvider' => $model->search(),
    'filter' => $model,
    'columns' => array(
    ...
    array(
        'class' => 'CButtonColumn',
        'template' => '{lots}',
        'header' => 'Lots',
        'buttons' => array(
            'lots' => array(
                'label' => 'Lots',
                'imageUrl' => Yii::app()->request->baseUrl.'/img/....png',
                'url' => 'Yii::app()->createUrl("controller1/lotlistbymainid", array("id" => $data->id))',
                'visible' => 'count($data->lots) > 0',
            ),
        ),
    ),

ここにある「buttons」配列を介して渡されるボタンパラメータの説明。特にこの部分:

ボタンのプロパティ

パブリック配列$buttons;

追加ボタンの構成。各配列要素は、次の形式の単一のボタンを指定します。

'buttonID' => array(
    'label'=>'...',     // text label of the button
    'url'=>'...',       // a PHP expression for generating the URL of the button
    'imageUrl'=>'...',  // image URL of the button. If not set or false, a text link is used
    'options'=>array(...), // HTML options for the button tag
    'click'=>'...',     // a JS function to be invoked when the button is clicked
    'visible'=>'...',   // a PHP expression for determining whether the button is visible
)
于 2012-07-27T04:21:44.257 に答える