某些magento函数无法在magento外部工作(ajax页面)
我试图使用ajax来放置特定属性(制造商)的产品列表 在我的ajax页面中,我尝试使用某些magento函数无法在magento外部工作(ajax页面),magento,Magento,我试图使用ajax来放置特定属性(制造商)的产品列表 在我的ajax页面中,我尝试使用 $this->__('hi'); //not working 错误 致命错误:在第24行的/home/shared/nftn/nftn/js/ajax/ajax_designer.php中不在对象上下文中时使用$this mage:__('hi'); //not working 错误 致命错误:在第23行的/home/shared/nftn/nftn/js/ajax/ajax_designer.ph
$this->__('hi'); //not working
错误
致命错误:在第24行的/home/shared/nftn/nftn/js/ajax/ajax_designer.php中不在对象上下文中时使用$this
mage:__('hi'); //not working
错误
致命错误:在第23行的/home/shared/nftn/nftn/js/ajax/ajax_designer.php中调用未定义的方法Mage::u()
我在页面顶部添加了所需的文件
require "../../app/Mage.php";
umask(0);
Mage::app('default');
$layout = Mage::getSingleton('core/layout');
即使这些功能也不起作用
Mage::stripTags()
Mage::getLayout()
问题是什么?我怎样才能让它工作
谢谢显然,
$这个
没有任何意义,因为你不是从一个对象中使用它。所有的助手都有这些功能,这里我使用的是'core'
,因为它是最通用的,但是如果您是为自己的模块编写的,那么就使用模块的助手-它有助于翻译
Mage::helper('core')->__('hello');
Mage::helper('core')->stripTags('world');
getLayout()
无法从外部文件工作,因为没有与页面关联的路由器/控制器/操作,因此没有要使用的布局
更长但更正确的方法是使用Magento的控制器,而不是外部文件。假设您的模块是
myu模块
,AJAX URL是www.example.com/mymodule/AJAX/
app/code/local/My/Module/etc/config.xml
<config>
<frontend>
<routers>
<mymodule>
<use>standard</use>
<args>
<module>My_Module</module>
<frontName>mymodule</frontName>
</args>
</mymodule>
</routers>
</frontend>
</config>
标准
My_模块
mymodule
app/code/local/My/Module/controllers/AjaxController.php
<?php
class My_Module_AjaxController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->getResponse()->setBody($this->__('hi'));
}
}
:谢谢**Mage::helper('core')->**这很好用。但是我不知道如何使用getLayout()。请帮我解释一下如何使它工作。我认为getLayout()
不能在外部文件中使用,至少我不知道有什么方法。