繁体   English   中英

Magento后端扩展无法打开流:没有此类文件或目录

[英]Magento backend extension failed to open stream: No such file or directory

我正在尝试为magento编写我的第一个扩展名。 因此,我将通过一些教程来弄清楚。

但是,在后端配置中显示一些选项时遇到了问题。

我的目录看起来像这样

--R2retail  
  /--HelloWorldTut  
     /--Block  
     /--controllers  
     /--etc  
        /--config.xml  
        /--system.xml  
     /--Helper
        /--Data.php
     /--Model
        /--Options.php
     /--sql

我只列出了此处相关的文件。

我在/app/etc/modules/ R2retail_HelloWorldTut文件如下所示

<?xml version="1.0"?>
   <config>
      <modules>
        <R2retail_HelloWorldTut>
            <active>true</active>
            <codePool>local</codePool>
         </R2retail_HelloWorldTut>
       </modules>
    </config>

我的config.xml看起来像这样

<?xml version="1.0"?>
  <config>
     <modules>
        <R2retail_HelloWorldTut>
          <version>0.1.0</version>
        </R2retail_HelloWorldTut>
     </modules>
     <global>
        <helpers>
          <helloworldtut>
            <class>R2retail_HelloWorldTut_Helper</class>
          </helloworldtut>
        </helpers>
        <models>
          <class>R2retail_HelloWorldTut_Model</class>
        </models>
     </global>
     <frontend>
       <routers>
          <helloworldtut>
              <use>standard</use>
              <args>
                 <module>R2retail_HelloWorldTut</module>
                 <frontName>helloworld</frontName>
              </args>
           </helloworldtut>
       </routers>
    </frontend>
    <adminhtml>
      <acl>
        <resources>
          <admin>
            <children>
              <config>
                <children>
                  <helloworldtut_options>
                    <title>R2retail Modules</title>
                  </helloworldtut_options>
                </children>
              </config>
            </children>
          </admin>
        </resources>
      </acl>
    </adminhtml>
</config>

我的system.xml看起来像这样(我怀疑错误在此处)

<?xml version="1.0"?>
<config>
    <tabs>
        <helloworldtut translate="label" module="helloworldtut">
            <label>Custom Configuration Tab</label>
            <sort_order>1</sort_order>
        </helloworldtut>
    </tabs>

    <sections>
        <helloworldtut_options translate="label" module="helloworldtut">
            <label>Custom Configuration Settings</label>
            <tab>helloworldtut</tab>
            <frontend_type>text</frontend_type>
            <sort_order>1</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>1</show_in_store>
            <groups>
                <section_one translate="label">
                    <label>Section One</label>
                    <frontend_type>text</frontend_type>
                    <sort_order>1</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <fields>
                        <custom_field_one>
                            <label>Custom Text Field</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>1</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                            <comment>Example of text field.</comment>
                        </custom_field_one>
                    </fields>
                </section_one>
                <secttion_two translate="label">
                    <label>Section Two</label>
                    <frontend_type>text</frontend_type>
                    <sort_order>2</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <fields>
                        <custom_field_two>
                            <label>Custom Select Field</label>
                            <frontend_type>select</frontend_type>
                            <source_model>helloworldtut/options</source_model>
                            <sort_order>1</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                            <comment>Example of select field.</comment>
                        </custom_field_two>
                        <custom_field_three>
                            <label>Custom Radio Field</label>
                            <frontend_type>radios</frontend_type>
                            <source_model>helloworldtut/options</source_model>
                            <sort_order>1</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                            <comment>Example of Radio Buttons</comment>
                        </custom_field_three>
                        <custom_field_four>
                            <label>Custom Multiselect Field</label>
                            <frontend_type>multiselect</frontend_type>
                            <source_model>helloworldtut/options</source_model>
                            <sort_order>1</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                            <comments>Example of Multiselect field</comments>
                        </custom_field_four>
                    </fields>
                </secttion_two>
            </groups>
        </helloworldtut_options>
    </sections>
</config>

当我注释掉第二部分时。 配置页面加载没有任何问题。 所以我一旦<source_model>helloworldtut/options</source_model>就会出错

我的Data.php看起来像这样

<?php
/**
 * Sample Widget Helper
 */
class R2retail_HelloWorldTut_Helper_Data extends Mage_Core_Helper_Abstract
{
}

最后我的Options.php看起来像这样

<?php
class R2retail_HelloWorldTut_Model_Options {
  /**
   * Provide available options as a value/label array
   *
   * @return array
   */
  public function toOptionArray()
  {
    return array(
      array('value'=>1, 'label'=>'One'),
      array('value'=>2, 'label'=>'Two'),
      array('value'=>3, 'label'=>'Three'),            
      array('value'=>4, 'label'=>'Four')                     
    );
  }
}

我希望有人能帮助我弄清楚我要去哪里错了

我尚未测试您的代码,但您可能对导致问题的源模型是正确的。

您引用模型别名:

<source_model>helloworldtut/options</source_model>

但是别名没有定义-也许您过于匆忙地完成了模型定义?

<models>
    <class>R2retail_HelloWorldTut_Model</class>
</models>

需要有一个别名:

<models>
    <helloworldtut>
        <class>R2retail_HelloWorldTut_Model</class>
    </helloworldtut>
</models>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM