1

test.php

<?php

require_once 'app/Mage.php';

Mage::init();

$product=new TutsPlus_Demo_Model_Product;
$product->sayHello();

$product1 = Mage::getModel("demo/product");
 $product1->sayHello();

echo get_class($product1);

config.xml

<config>
    <global>
        <models>
            <demo>
                <class>TutsPlus_Demo_Model</class> 
            </demo>
        </models>
    </global>
 </config>

product.php

<?php

class TutsPlus_Demo_Model_Product{

    public function sayHello(){

        echo "Hello Hi how are you"; 
    }
}
5
  • 2
    do you have the declaration file app/etc/modules/TutsPlus_Demo.xml ?
    – Marius
    Commented Oct 17, 2014 at 7:09
  • 1
    @Marius : should it be Mage::app() instead of Mage::init() ? Commented Oct 17, 2014 at 7:13
  • @programmer_rkt. I usually use Mage::app().
    – Marius
    Commented Oct 17, 2014 at 7:17
  • @Marius : you mean Mage::init() also work ? I am also normally using Mage::app() Commented Oct 17, 2014 at 7:18
  • @programmer_rkt. I didn't try it, but it should work. It is used in api.php and get.php.
    – Marius
    Commented Oct 17, 2014 at 7:20

5 Answers 5

4

Try below things.

  1. As marius commented out, make sure the activation file exist

File : app/etc/modules/TutsPlus_Demo.xml and its content should be

<config>
    <modules>
        <TutsPlus_Demo>
            <active>true</active>
            <codePool>local</codePool>
        </TutsPlus_Demo>
    </modules>
</config>
  1. Make sure the model path looks like this. Beware capital letters

File : app/code/local/TutsPlus/Demo/Model/Product.php

  1. At last, try to use Mage::app() instead of Mage::init()
1

I am not sure, But I think you should use

Mage::app();

Instead of

Mage::init();
1

You should change

Mage::init()

to

Mage::run()

1
  • Maybe add some more information as to why to change it?
    – rob3000
    Commented Nov 5, 2015 at 0:23
0

Try these which worked for me:

  1. Please don't use capital letters in XML nodes/tags in config.xml file.
  2. Remove <?xml version="1.0" ?> in config.xml
  3. it looks like you saved as product.php, make "P" caps because "TutsPlus_Demo_Model_Product". your class is defined in Product.php file.
1
  • I personally disagree with point 1 and 2 here.
    – scrowler
    Commented Nov 5, 2015 at 3:42
0

This worked for me. If the module class was recently instantiated do the following:

  1. Flush Magento Cache and Flush Cache Storage
  2. Delete the contents of var/cache folder
  3. Try again

Hope this works for you.

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.