Php 从另一个模块的模板文件调用自定义模块帮助器
我已经创建了一个新模块。该模块与另一个数据库连接。现在我想从另一个模块模板文件调用helper类,比如“description.pthml”。我使用了以下代码Php 从另一个模块的模板文件调用自定义模块帮助器,php,magento,module,Php,Magento,Module,我已经创建了一个新模块。该模块与另一个数据库连接。现在我想从另一个模块模板文件调用helper类,比如“description.pthml”。我使用了以下代码 $_helper = $this->helper('ForumProdPosts/output'); class MyWebsite_ForumProdPosts_Helper_Output extends Mage_Core_Helper_Abstract { /** * Constructor */
$_helper = $this->helper('ForumProdPosts/output');
class MyWebsite_ForumProdPosts_Helper_Output extends Mage_Core_Helper_Abstract
{
/**
* Constructor
*/
public function __construct()
{
Mage::dispatchEvent('forumprodposts_helper_output_construct', array('helper'=>$this));
}
public function getForumPosts(){
echo "I m here";
exit;
}
}
但我得到了错误“致命错误:在第546行的/home/black/public_html/app/Mage.php中找不到类'Mage_ForumProdPosts_Helper_Output'
helper类位于local/MyWebsite/ForumProdPosts/helper/Output.php中,包含以下代码
$_helper = $this->helper('ForumProdPosts/output');
class MyWebsite_ForumProdPosts_Helper_Output extends Mage_Core_Helper_Abstract
{
/**
* Constructor
*/
public function __construct()
{
Mage::dispatchEvent('forumprodposts_helper_output_construct', array('helper'=>$this));
}
public function getForumPosts(){
echo "I m here";
exit;
}
}
我的模块的config.xml也是
<?xml version="1.0"?>
<config>
<modules>
<MyWebsite_ForumProdPosts>
<version>0.1.0</version>
</MyWebsite_ForumProdPosts>
</modules>
<frontend>
<routers>
<forumprodposts>
<use>standard</use>
<args>
<module>MyWebsite_ForumProdPosts</module>
<frontName>forumprodposts</frontName>
</args>
</forumprodposts>
</routers>
<layout>
<updates>
<forumprodposts>
<file>forumprodposts.xml</file>
</forumprodposts>
</updates>
</layout>
</frontend>
<global>
<helpers>
<forumprodposts>
<class>MyWebsite_ForumProdPosts_Helper</class>
</forumprodposts>
</helpers>
<resources>
<forumprodposts_write>
<connection>
<use>phpbb_database</use>
</connection>
</forumprodposts_write>
<forumprodposts_read>
<connection>
<use>phpbb_database</use>
</connection>
</forumprodposts_read>
<forumprodposts_setup>
<connection>
<use>core_setup</use>
</connection>
</forumprodposts_setup>
<forumprodposts_database>
<connection>
<host><![CDATA[localhost]]></host>
<username><![CDATA[user]]></username>
<password><![CDATA[password]]></password>
<dbname><![CDATA[forumdb]]></dbname>
<model>mysql4</model>
<type>pdo_mysql</type>
<active>1</active>
</connection>
</forumprodposts_database>
</resources>
</global>
</config>
0.1.0
标准
我的网站
用于UMPRODPPOST
forumprodposts.xml
我的网站\u ForumProdPosts\u助手
phpbb_数据库
phpbb_数据库
核心单元设置
mysql4
pdo_mysql
1.
在我看来,magento不认识我的模块。帮帮我,我做错了什么
我刚刚意识到我的模块没有出现在管理面板的配置/高级部分。我已经完成了重新索引和清除现金,我的网站&u ForumProdPosts.xml在etc/modules中有以下代码
<?xml version="1.0"?>
<config>
<modules>
<MyWebsite_ForumProdPosts>
<active>true</active>
<codePool>local</codePool>
</MyWebsite_ForumProdPosts>
</modules>
</config>
真的
地方的
我认为命名约定必须与config.xml中定义的名称匹配。
因此,请尝试下面给出的代码
$_helper = $this->helper('forumprodposts/output');
// all in small letter as defined in your xml file
Mage::helper()
方法用于config.xml中的xml节点,而不是模块名称
当Magento启动时,所有config.xml都连接到一个大xml文件中。在该文件中,“全局/帮助器”节点包括在所有模块中定义的所有帮助器。helper方法使用这些节点加载正确的类:
public static function helper($name)
{
$registryKey = '_helper/' . $name;
if (!self::registry($registryKey)) {
$helperClass = self::getConfig()->getHelperClassName($name);
self::register($registryKey, new $helperClass);
}
return self::registry($registryKey);
}
因此,要访问MyWebsite\u for umprodposts\u Helper\u Output
,您必须编写:
$_helper = $this->helper('forumprodposts/output');
仍然不起作用。模块XML中是否存在任何问题,因为该模块在管理面板中也没有显示configuration/advanced(配置/高级)您是否从app/etc/modules/MyWebsite_ForumProdPosts.XML中激活了您的模块,并删除了缓存并重新编制了索引。请再试一件事。您可以使用MyWebsite_ForumProdPosts(我的网站_用于umprodposts),而不是在模块名称中使用MyWebsite_ForumProdPosts,并将其激活,然后检查其是否处于激活状态?0.1.0..在app/etc/Mywebsite_Forumprodposts.xml中执行相同的更改。它现在显示并处于活动状态。但是helper错误仍然存在。我已经将config.xml中的ForumProdPosts的所有实例都更改为ForumProdPosts,在Mywebsite_ForumProdPosts.xml中也更改为ForumProdPosts,但仍然是相同的错误。您是否创建了etc/modules/Mywebsite_ForumProdPosts.xml这样的文件?true local如果是,请尝试简化xml,并使用Mage::getConfig()制作一个测试文件,检查模块是否出现在Magento配置中;