doulei8475 2017-02-04 12:25
浏览 42
已采纳

Magento后端扩展无法打开流:没有这样的文件或目录

I'm trying to write my first extension for magento. So I'm going through some tutorials to figure it out.

However I'm running into a problem with displaying some options in the backend configuration.

My directory looks like this

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

I only listed the files that are relevant here.

My R2retail_HelloWorldTut file that is in /app/etc/modules/ looks as follows

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

my config.xml looks like this

<?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>

My system.xml looks like this (I suspect the error is here somewhere)

<?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>

When I comment out the second section. the configuration page loads without any problems. so it goes wrong as soon as I do <source_model>helloworldtut/options</source_model>

My Data.php looks like this

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

and finally my Options.php looks like this

<?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')                     
    );
  }
}

I hope someone can help me figure out where I'm going wrong

  • 写回答

1条回答 默认 最新

  • dougu4704 2017-02-04 21:40
    关注

    I haven't tested your code, but you're probably right about the source model causing the problem.

    You reference a model alias:

    <source_model>helloworldtut/options</source_model>
    

    Yet the alias is not defined - perhaps you rushed through your model definition a little too quickly?

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

    Needs to have an alias:

    <models>
        <helloworldtut>
            <class>R2retail_HelloWorldTut_Model</class>
        </helloworldtut>
    </models>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于温度改变石墨烯介电性能(关键词-介电常数)
  • ¥150 HDMI分路器LT86102 的输出在890MHz频点处EMC超标8DB
  • ¥15 druid(相关搜索:数据库|防火墙)
  • ¥15 大一python作业
  • ¥15 preLaunchTask"C/C++: aarch64- apple-darwin22-g++-14 生成活动 文件”已终止,退出代码为-1。
  • ¥60 如何鉴定微信小程序数据被篡改过
  • ¥18 关于#贝叶斯概率#的问题:这篇文章中利用em算法求出了对数似然值作为概率表参数,然后进行概率表计算,这个概率表是怎样计算的呀
  • ¥20 C#上传XML格式数据
  • ¥15 elementui上传结合oss接口断点续传,现在只差停止上传和继续上传,各大精英看下
  • ¥20 手机截图相片分辨率降低一半