在magento的现有模块中添加块

发布于 2024-10-02 00:05:13 字数 962 浏览 3 评论 0原文

我定制了客户模块来满足我的要求。我能够重写客户模块的块类。我正在尝试在此模块中添加一个自定义块类,该类在现有客户模块中不存在,但我不知道如何实现这一点。

我的代码看起来像在 config.xml 中,

 <blocks>            
        <customer>
           <rewrite>                          
<widget_name>Mynamespace_Customer_Block_Widget_Name</widget_name>                   
<form_register>Mynamespace_Customer_Block_Form_Register</form_register>
<form_edit>Mynamespace_Customer_Block_Form_Edit</form_edit>
           </rewrite>                   
        </customer>  

     </blocks>

我在客户模块的 Form 目录下创建了一个名为“Test.php”的新块类

,客户布局文件看起来像

<reference name="my.account.wrapper">
            <block type="customer/form_test" name="customer_test" template="customer/form/test.phtml"/>
        </reference>   

但它没有执行块类文件。 该模块的 config.xml 文件中是否需要添加任何内容?

请帮助如何将此块与现有模块集成。

谢谢。

I have customized customer module to meet my requirement. I am able to rewrite block classes of customer module. I am trying to add one custom block class in this module which is not exists in existing customer module but I don't know how to accomplish this.

my code looks like in config.xml

 <blocks>            
        <customer>
           <rewrite>                          
<widget_name>Mynamespace_Customer_Block_Widget_Name</widget_name>                   
<form_register>Mynamespace_Customer_Block_Form_Register</form_register>
<form_edit>Mynamespace_Customer_Block_Form_Edit</form_edit>
           </rewrite>                   
        </customer>  

     </blocks>

I created a new block class under the Form directory of customer module called 'Test.php'

And customer layout file looks like

<reference name="my.account.wrapper">
            <block type="customer/form_test" name="customer_test" template="customer/form/test.phtml"/>
        </reference>   

But it is not executing the block class file.
Is there anything should be added in config.xml file of this module?

Please help how this block can be integrated with existing module.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烈酒灼喉 2024-10-09 00:05:13

您实际上不应该将块添加到客户模块中,您应该将它们添加到您自己的模块中。如果您想继续使用客户模块,请检查并确保您的块被命名为 Mage_Customer_Block_Form_Test 并扩展 Mage_Core_Block_Template。否则,将该类创建为 Mynamespace_Customer_Block_Form_Test 并将其保存在模块目录中。然后,在 config.xml 中为您的类添加块定义:

<blocks>
  <mynamespace_customer>
    <class>Mynamespace_Customer_Block</class>
  </mynamespace_customer> 
</blocks>

然后您应该能够将块加载为 mynamespace_customer/form_test

如果您使用 customer 以外的模块名称,则调试问题可能会更容易。一般来说,这是一个坏主意,并且可能会导致系统出现错误。

希望有帮助!

谢谢,

You shouldn't really be adding blocks to the customer module, you should be adding them to your own module. If you want to keep on w/ the customer module, check to make sure that your block is named as Mage_Customer_Block_Form_Test and extends Mage_Core_Block_Template. Otherwise, create the class as Mynamespace_Customer_Block_Form_Test and keep it in your module directory. Then, add a block definition for your class in config.xml:

<blocks>
  <mynamespace_customer>
    <class>Mynamespace_Customer_Block</class>
  </mynamespace_customer> 
</blocks>

Then you should be able to load the block as mynamespace_customer/form_test.

It may be easier to debug your problem if you use a module name other than customer. Generally speaking, that is a bad idea and will likely cause bugs in the system.

Hope that helps!

Thanks,
Joe

〆一缕阳光ご 2024-10-09 00:05:13

您可能已经意识到这一点,但考虑检查 LayoutViewer 以查看布局认为正在使用。

虽然我确信您的示例 config.xml 只是一个示例,但请确保您记得为 form_test 创建重写,并且您自己的模块有一个有效的块部分。

顺便说一句,LayoutViewer 确实可以为 Magento Connect 正确打包。链接文件缺少启用该模块所需的配置,如果可以从 PEAR 访问它会更有用。

You may already be aware of this but think about checking LayoutViewer to see what the layout thinks it is using.

Although I'm sure your example config.xml is just an example please make sure that you've remembered to create a rewrite for form_test and that there is a valid blocks section for your own module.

BTW, LayoutViewer could really do with being packaged properly for Magento Connect. The linked file lacks the necessary config to enable the module and it would be much more useful if accessible from PEAR.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文