-3

I am using Magento 1.9.2.0 I have created the module to display the products

$arr_products = array();
$products = Mage::getModel("recentproducts/recentproducts")->getRecentProducts();

foreach ($products as $product) {

 $arr_products[] = array(
    'id' => $product->getId(),
    'name' => $product­>getName(),
    'url' => $product­>getProductUrl(),
  );
}

return $arr_products;

Error: Fatal error: Call to undefined function getName()

Any one please help to solve the error

8
  • please show full code.. cannot find the function getData() in the code..
    – Amit Bera
    Commented Jul 13, 2015 at 12:34
  • Hi i am new to magento this is the block folder file what file did u need Commented Jul 13, 2015 at 12:35
  • where you have wrote code getData() i?
    – Amit Bera
    Commented Jul 13, 2015 at 12:36
  • I am not written "getData" function i thing this default function Commented Jul 13, 2015 at 12:38
  • 3
    product­>getName(), is missing a - so it reads product­ "greater than" getName(), - and getName() is not a function. Commented Jul 13, 2015 at 12:42

1 Answer 1

-1

Your code seem to contain a typo as pointed out by @fschmengler in the comments.

The row:

    'name' => $product­>getName(),

What you really want is:

    'name' => $product->getName(),

The original typo makes the code tell PHP to compare $product with output of a function called getName() using greater than operator ">", (instead of calling the method getName() on the object $product which is what you want to do.)

That's why it says it can't find function getName().

1
  • Down voted AND marked as correct answer. Nice.
    – kb.
    Commented May 25, 2016 at 10:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.