【发布时间】:2019-06-21 21:08:01
【问题描述】:
我正在 Magento 中构建我的第一个模块,并且有几个与该过程相关的问题。
在我尝试一个模块之前,我只有一个模板,并使用此代码将其加载到 app\design\frontend\rwd\default\layout\local.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="after_body_start">
<block type="checkout/cart_sidebar" template="mgw/mwCartRebuild.phtml"/>
</reference>
</default>
</layout>
生活很美好,一切正常,直到我决定需要扩展 Mage_Checkout_Block_Cart_Sidebar 类。
所以我创建了一个模块来做到这一点。这是我的代码。
屏蔽 app\code\local\mgw\Cart\Block\ModalCart.php
<?php
class mgw_Cart_Block_Modal_Cart extends Mage_Checkout_Block_Cart_Sidebar{
public function __construct(){
perent::__construct();
$this->setTemplate('mgw/mwCartRebuild.phtml');
}
}
config.xml app\code\local\mgw\Cart\etc\config.xml
<config>
<global>
<modules>
<mgw_Cart>
<version>0.0.0</version>
</mgw_Cart>
</modules>
<blocks>
<mgw_Cart>
<class>mgw_Cart_Block_Modal_Cart</class>
</mgw_Cart>
</blocks>
<helpers>
<cart>
<class>mgw_Cart_Helper</class>
</cart>
</helpers>
</global>
</config>
新的 local.xml app\design\frontend\rwd\default\layout\local.xml
<layout version="0.1.0">
<default>
<reference name="after_body_start">
<block type="cart/modal_cart"/>
</reference>
</default>
</layout>
模块 xml app\etc\modules\mgw_Cart.xml
<config>
<modules>
<mgw_Cart>
<active>true</active>
<codePool>local</codePool>
<depends />
</mgw_Cart>
</modules>
</config>
现在我的模板无法加载。我已经检查了管理员以查看我的模块是否正在加载并已列出。那么为什么我的模板无法加载呢?
我的问题是:
- 我什至可以像我尝试的那样扩展核心块吗?
- 如何让我的块/模板加载?
【问题讨论】: