我是Dark Arts(1.9)的亲戚,我对模块加载块的顺序有疑问。
我有一个块应由我的其他块加载(它们扩展它):
块/ Javascript.php:
class MyNamespace_MyModule_Block_Javascript extends MyNamespace_MyModule_Block_MyModule
块/ Mymodule.php:
class MyNamespace_MyModule_Block_MyModule extends Mage_Core_Block_Template
所有在我的开发堆栈上工作得很好,所以我将代码同步(仔细排除app / etc / local.xml等文件)
但是,当我将模块rsync到测试服务器时,Block / Javascript.php无法找到基本块类(MyNamespace_MyModule_Block_MyModule)并返回异常..但它在我的开发堆栈上工作正常。
编辑:例外是
Fatal error: Class 'MyNamespace_MyModule_Block_MyModule' not found in
/var/www/magento/app/code/community/MyNamespace/MyModule/Block/Javascript.php
on line 7
它在我的本地开发堆栈上工作正常 - 模型,块,帮助器和资源都在config.xml中正确设置
我不得不强制加载基块以使其工作,这实际上并不是我认为最好的方式..
Mymodule.php:
if (!class_exists('MyNamespace_MyModule_Block_MyModule'))
{
class MyNamespace_MyModule_Block_MyModule extends Mage_Core_Block_Template
{
}
}
..由Javascript.php扩展:
if (!class_exists('MyNamespace_MyModule_Block_MyModule'))
require_once dirname(__FILE__).'/Mymodule.php';
class MyNamespace_MyModule_Block_Javascript extends MyNamespace_MyModule_Block_MyModule
{
}
此外,任何有关从dev快速部署到测试服务器的最佳方法的建议都将受到赞赏(repo是git,.gitignore文件忽略了它所需的一切)
编辑:
config.xml中
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<MyNamespace_MyModule>
<version>2.0.0</version>
</MyNamespace_MyModule>
</modules>
<global>
<models>
<mymodule>
<class>MyNamespace_MyModule_Model</class>
<resourceModel>mymodule_resource</resourceModel>
</mymodule>
<mymodule_mysql4>
<class>MyNamespace_MyModule_Model_Resource_Mysql4</class>
<entities>
<mymodule>
<table>mymodule</table>
</mymodule>
</entities>
</mymodule_mysql4>
</models>
<blocks>
<mymodule>
<class>MyNamespace_MyModule_Block</class>
</mymodule>
</blocks>
<helpers>
<mymodule>
<class>MyNamespace_MyModule_Helper</class>
</mymodule>
</helpers>
<resources>
<mymodule_setup>
<setup>
<module>MyNamespace_MyModule</module>
<class>MyNamespace_MyModule_Model_Resource_Mysql4_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</mymodule_setup>
<mymodule_write>
<connection>
<use>core_write</use>
</connection>
</mymodule_write>
<mymodule_read>
<connection>
<use>core_read</use>
</connection>
</mymodule_read>
</resources>
</global>
<frontend>
<routers>
<mymodule>
<use>standard</use>
<args>
<module>MyNamespace_MyModule</module>
<frontName>mymodule</frontName>
</args>
</mymodule>
</routers>
<layout>
<updates>
<mymodule>
<file>mymodule.xml</file>
</mymodule>
</updates>
</layout>
</frontend>
<admin>
<routers>
<mymodule>
<use>admin</use>
<args>
<module>MyNamespace_MyModule</module>
<frontName>mymodule</frontName>
</args>
</mymodule>
</routers>
</admin>
<default>
<mymodule>
<receipted>optional</receipted>
<assurance>optional</assurance>
<tailliftto>optional</tailliftto>
<tailliftfrom>50></tailliftfrom>
<handling_type>none></handling_type>
<type>Carton</type>
<handling_fee>0</handling_fee>
<tailliftto>0</tailliftto>
<tailliftfrom>0</tailliftfrom>
<assurance>optional</assurance>
</mymodule>
<carriers>
<mymodule>
<active>0</active>
<model>mymodule/shipping_carrier_mymodule</model>
<title>Courier</title>
<showmethod>1</showmethod>
<sort_order>5</sort_order>
<sallowspecific>0</sallowspecific>
<specificcountry>AU</specificcountry>
<specificerrmsg>Error when retrieving real-time shipping quotes</specificerrmsg>
</mymodule>
</carriers>
</default>
</config>
..和layout / mymodule.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<default>
<reference name="head">
<block type="core/text"
name="google.cdn.jquery"> <!-- Ensure that jQuery is active with no-conflict set to $j -->
<action method="setText">
<text><![CDATA[<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script><script>window.jQuery||document.write('<script src="/js/mymodule/jquery-ui/external/jquery/jquery.js">\x3c/script>');</script><script>var $j = jQuery.noConflict();</script>]]></text>
</action>
</block>
</reference>
</default>
<checkout_cart_index>
<reference name="content"><!-- Inserts a list of Australian towns for autcomplete -->
<block type="mymodule/javascript" name="mymodule.javascript.towns"
template="mymodule/mymodule/jstowns.phtml">
</block>
</reference>
<reference name="head">
<action method="addCss">
<stylesheet>mymodule/jquery-ui.min.css</stylesheet>
</action>
<action method="addCss">
<stylesheet>mymodule/jquery-ui.theme.min.css</stylesheet>
</action>
<action method="addJs">
<script>mymodule/jquery-ui/jquery-ui.min.js</script>
</action>
<action method="addJs">
<script>mymodule/cart-complete.js</script>
</action>
</reference>
</checkout_cart_index>
<checkout_onepage_index>
<reference name="content"><!-- Inserts a list of Australian towns for autcomplete -->
<block type="mymodule/javascript" name="mymodule.javascript.towns"
template="mymodule/mymodule/jstowns.phtml"/>
</reference>
<reference name="head">
<action method="addCss">
<stylesheet>mymodule/jquery-ui.min.css</stylesheet>
</action>
<action method="addCss">
<stylesheet>mymodule/jquery-ui.theme.min.css</stylesheet>
</action>
<action method="addJs">
<script>mymodule/jquery-ui/jquery-ui.min.js</script>
</action>
<action method="addJs">
<script>mymodule/onepage-complete.js</script>
</action>
</reference>
</checkout_onepage_index>
<checkout_onepage_shippingmethod>
<reference name="content">
<block name="mymodule.shipping.options" type="mymodule/onepage_shipping_method_options"
template="mymodule/mymodule/Onepage/Shipping/Method/Options.phtml" output="toHtml"/>
</reference>
</checkout_onepage_shippingmethod>
</layout>
干杯。