質問

admin grid.phpを使用しているモジュールを作成しました。データを追加および取得するための3つのテーブルを作成しましたが、Grid.phpファイルのドロップダウン選択内部に表示されるモデルからデータを取得することはできません。

私が抱えている問題は、何らかの理由で、ドロップダウン選択で表示するためにテーブルからデータを取得できないということです。

以下のコードを参照してください:

  $this->addColumn("region", array(
            "header" => Mage::helper("modulename")->__("Region"),
            "type" => 'options',
            'options'=> Mage::getModel('modulename/region')->getRegions()
            ));  

上記はグリッドに領域列を追加し、私のモデルからデータを取得します

モデル/region.php

 protected function _construct(){

       $this->_init("modulename/region");

    }

    public function getRegions() {

        $regionsArray = array();
        foreach($this->getCollection() as $region){
        $regionsArray[$region->getId()] = $region->getTitle();

        }
        return $regionsArray;

    }

ただし、次の列が問題を引き起こしているものです

        $this->addColumn('state', array(
        'header' => Mage::helper('modulename')->__('State'),
        'index' => 'state',
        'type' => 'options',
        'options'=> Mage::getModel('modulename/customerstate')->getState()
        ));

オプション内に表示するモデルからデータを取得できないようです

protected function _construct(){

   $this->_init("modulename/customerstate");

}

public function getStates() {

    $statesArray = array();
    foreach($this->getCollection() as $state){
    $statesArray[$state->getId()] = $state->getState();

    }
    return $statesArray;

}

顧客はDBテーブルを設定します

+-------+----------+
|  s_id | state    |
+-------+----------+
|     1 | pending  |
|     2 | active   |
+-------+----------+

なぜこれが起こっているのか、私は何時間もサークルで回っていたので、これを解決するためにいくつかのアドバイスをすることができます - グリッドの空の選択オプションだけがエラーが発生していません...

役に立ちましたか?

解決

@Kalpesh Mehtaと@Mariusの貢献に感謝します。

以前の投稿で述べたように、以下のコードでエラーを解決しました。->getState() それ以外の ->getStates()

grid.php

            $this->addColumn('state', array(
            'header' => Mage::helper('modulename')->__('State'),
            'index' => 'state',
            'type' => 'options',
            'options'=> Mage::getModel('modulename/customerstate')->getStates()
            ));

Model/customerState.php

  public function getStates() {

        $statesArray = array();
        foreach($this->getCollection() as $state){
            $statesArray[$state->getId()] = $state->getState();

        }
        return $statesArray;

    }

他のヒント

一見、あなたは正しい軌道に乗るように縫います。
エラーが示唆するように、問題は次のとおりです。

Mage::getSingleton('my/modulename')

おそらくこれは戻ってきます null.
あなたが投稿したコードから、私はそれを結論付けることができます My あなたの名前空間ですか? Module モジュール名(duh!)です。
Iこれは上記のコードが必要です:

Mage::getSingleton('module/[entity_name_here]');

どこ [entity_name_here] あなたのエイリアスであるべきです region モデル

ライセンス: CC-BY-SA帰属
所属していません magento.stackexchange
scroll top