2015-11-02 09:07
浏览 48

Magento - 在块模板中未定义变量

I am making a simple magento block and a template for it.

In my custom module I have a config.xml

<?xml version="1.0"?>

And this is my Block

class AAA_Recentproducts_Block_Recentproducts extends Mage_Core_Block_Template {
  public function getRecentProducts() {
    $products = Mage::getModel("catalog/product")
                    ->setOrder('entity_id', 'DESC')
    return $products;

And finally my template file:

$products = $this­->getRecentProducts();
//$products = [];

<div id="product_list">
  <h1>Recent Products</h1>
  <?php if (is_array($products) && count($products)) { ?>
    <?php foreach($products as $product) { ?>
    <?php } ?>
  <?php } ?>

The error I get is: 2015-11-02T08:53:55+00:00 ERR (3): Notice: Undefined variable: this­ in /var/www/html/magento/app/design/frontend/smartwave/granada/template/recentproducts/recentproducts.phtml on line 2

Does anyone have an idea why this error occurs?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题