首先,我必须为我在这个问题上缺乏知识而道歉。我对Magento还是个新手,有了这些信息,我应该可以让它工作。我开始here。我可以让ajax方法进行调用,但是我得到了一个空白的2column-left.phtml作为输出(所以我看到了页眉、左列、空白主列和页脚)。我的档案是这样设置的:
app/local/mymodule/featured/block/featured.php
<?php
class MyModule_Featured_Block_Featured extends Mage_Core_Block_Template
{
public function __construct()
{
$this->_controller = 'featured';
$this->_blockGroup = 'featured';
parent::__construct();
}
}
?>
app/local/mymodule/featured/controllers/featuredcontroller.php
<?php
class MyModule_Featured_FeaturedController extends Mage_Core_Controller_Front_Action
{
public function displayAction()
{
$this->loadLayout()->renderLayout();
}
}
?>
app/local/mymodule/featured/etc/config.xml文件
<config>
<modules>
<MyModule_Featured>
<version>0.1.0</version>
</MyModule_Featured>
</modules>
<frontend>
<routers>
<featured>
<use>standard</use>
<args>
<module>MyModule_Featured</module>
<frontName>featured</frontName>
</args>
</featured>
</routers>
</frontend>
</config>
app/design/frontend/default/mylayout/layout/local.xml
<config>
<featured_featured_display>
<block type="module/block" name="root" output="toHtml" template="catalog/product/featured.phtml" />
</featured_featured_display>
</config>
主页上的ajax代码自定义phtml:
var url = "<?php echo $this->getUrl('featured/featured/display') ;?>";
jQuery(document).ready(function() {
jQuery('#featured-products').load(url);
});
最佳答案
我认为布局文件的根节点应该是<layout>
而不是<config>
。
附笔。
如果你想做没有jQuery——避免臃肿- MaGeNTO已经有了Prototype作为标准,并且可以做完全一样。
var url = "<?php echo $this->getUrl('featured/featured/display') ?>";
document.observer('dom:loaded', function(){
new Ajax.Updater('featured-products', url);
});