1

I am new to Magento and following tutsplus tutorial. During module development I got this error "Call to a member function sayHello() on boolean".

Below is my test.php file in magento(for testing the module):

     require_once'app/Mage.php';          
     Mage::app();
     $customer= Mage::getModel("customer/session");

     //Mage_catalog_Model_Product

     Mage::getModel("catalog/product");

     $product = Mage::getModel("demo/product");

     $product -> sayHello();

Here is the model file code (Product.php)

      class Tutsplus_Demo_Model_Product {

       public function sayHello(){

       echo "Hi";
      }
     }

When I removed the $product->sayHello(); to // echo get_class($customer); it shows the class name. config.xml file is here.

     <config>
       <global>
         <models>
            <demo>
                <class>Tutsplus_Demo_Model</class>
            </demo>
         </models>
       </global>
      </config>
4
  • Capitalize your classname with Tutsplus_Demo_Model_Product Commented Aug 3, 2016 at 12:44
  • I changed the file name 'tutsplus' to 'Tutsplus' and also class name 'tutsplus_Demo_Model_Product' to 'Tutsplus_Demo_Model_Product'. Same issue.
    – Probe
    Commented Aug 3, 2016 at 12:49
  • remove extra space in $product->sayHello(); Commented Aug 3, 2016 at 12:52
  • Done. Same error.
    – Probe
    Commented Aug 3, 2016 at 12:55

1 Answer 1

0

app/etc/modules/Tutsplus_Demo.xml

<?xml version="1.0"?> 
 <config> 
   <modules> 
    <Tutsplus_Demo> 
     <active>true</active> 
     <codePool>local</codePool> 
     <version>0.1.0</version> 
    </Tutsplus_Demo> 
   </modules> 
 </config>

make sure you define model in app/code/local/Tutsplus/Demo/etc/config.xml

<?xml version="1.0"?>
    <config>
    <modules>
    <Tutsplus_Demo>
      <version>0.1.0</version>
    </Tutsplus_Demo>
  </modules>
    <global>
        <models>
            <demo>
                <class>Tutsplus_Demo_Model</class>
            </demo>
        </models>
     </global>
    </config>

finally your model app/code/local/Tutsplus/Demo/Model/Product.php

capitalize the first keyword and extends to Mage_Core_Model_Abstract

class Tutsplus_Demo_Model_Product extends Mage_Core_Model_Abstract
{
      public function sayHello(){

       echo "Hi";
      }

}

for calling the model

 $product = Mage::getModel("demo/product");
   $product->sayHello();
14
  • I changed this above code to my existing one but its still showing the same error.
    – Probe
    Commented Aug 3, 2016 at 12:54
  • can you add your module config.xml and Tutsplus_Demo.xml Commented Aug 3, 2016 at 12:56
  • yes. I did that to.
    – Probe
    Commented Aug 3, 2016 at 12:58
  • @Probe i mean add here in question Commented Aug 3, 2016 at 12:58
  • @Probe did your module listed in admin panel system > configuration > advanced Commented Aug 3, 2016 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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