システム構成カスタム ソース モデル エラー
-
13-12-2019 - |
質問
カスタムフィールド値を使用してシステム構成セクションを作成しようとしています
これは私のコードです:
system.xml
<?xml version="1.0"?>
<config>
<tabs>
<macerierconf translate="label">
<label>Macerier</label>
<sort_order>150</sort_order>
</macerierconf>
</tabs>
<sections>
<tab1 translate="label" module="adminhtml">
<label>Settings</label>
<tab>macerierconf</tab>
<sort_order>100</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<groups>
<smssending translate="label comment">
<label>test label</label>
<sort_order>60</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<device translate="label comment">
<label>Device</label>
<frontend_type>select</frontend_type>
<source_model>macerier_test/system_config_source_dropdown_values</source_model>
<sort_order>30</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
</device>
</fields>
</smssending>
</groups>
</tab1>
</sections>
</config>
config.xml
<?xml version="1.0"?>
<config>
<modules>
<Macerier_TEST>
<version>0.1.0</version>
</Macerier_TEST>
</modules>
<global>
<models>
<macerier_test>
<class>Macerier_TEST_Model</class>
</macerier_test>
</models>
</global>
</config>
それから
Macerier\TEST\Model\System\Config\Source\Dropdown\Values.php
私はこれを持っています:
<?php
class Macerier_TEST_Model_System_Config_Source_Dropdown_Values
{
public function toOptionArray()
{
return array(
array(
'value' => 'key1',
'label' => 'Value 1',
),
array(
'value' => 'key2',
'label' => 'Value 2',
),
);
}
}
そして私はこのエラーを受け取ります:
PHP の致命的なエラー:/home/user/public_html/magento/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php の 463 行目で、非オブジェクトのメンバー関数 toOptionArray() を呼び出します。
カスタムソースモデルなしでモジュールが動作しているため、ここで何か間違ったことをしていると確信しています。
解決
ドロップダウンでは取得できません ソースモデル
macerier_test/system_config_source_dropdown_values
それがエラーを表示する理由です
モデルプレフィックスを定義していない可能性があります。
あなたのコードに従って macerier_test
。モデルのプレフィックスです
そこでモデルプレフィックスを定義しましょう config.xml
config.xml
<?xml version="1.0"?>
<config>
<modules>
<Macerier_TEST>
<version>0.1.0</version>
</Macerier_TEST>
</modules>
<!-- add this -->
<global>
<models>
<macerier_test> <!-- call as model prefix identifier -->
<class>Macerier_TEST_Model</class>
</macerier_test>
</models>
</global>
</config>
所属していません magento.stackexchange