0

I am new with Magento. And trying to create my own model.
So I start with a small test
The model folder structure as the following:

FirstStore/Demo/block 
FirstStore/Demo/etc/config.xml
FirstStore/Demo/controller
FirstStore/Demo/Model/Product.php
FirstStore/Demo/Helper
FirstStore/Demo/sql

the etc/config.xml code:

<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
    <version>0.0.1</version>
</modules>
</config>

and the Model/Product.php code:

class FirstStore_Demo_Model_Product
{
public function sayhello(){
    echo 'Hello , World with Magento';
}
}

and the app/etc/modules/FirstStore_Demo.xml code:

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

finally I am running this code under test.php page at the magento root dir
the test.php code:

require_once 'app/Mage.php';
Mage::app();

$product = new FirstStore_Demo_Model_Product;
$product->sayhello();

the error at localhost/magento/test.php is:

Fatal error: Class 'FirstStore_Demo_Model_Product' not found in C:\xampp\htdocs\php\magento\test.php

7
  • is your FirstStore folder located in app/code/local or at least app/code/community ?
    – Marius
    Commented May 5, 2015 at 13:27
  • please add replace your config.xml with <?xml version="1.0" encoding="UTF-8"?> <config> <FirstStore_Demo> <modules> <version>0.0.1</version> </modules> </FirstStore_Demo> <global><models><firststore_demo><class>FirstStore_Demo_Model</class></firststore_demo></models></global> </config> and call the model with $product = Mage::getModel('firststore_demo/product'); to see what happens Commented May 5, 2015 at 13:30
  • @Marius at app/code/local Commented May 5, 2015 at 13:30
  • @SanderMangel still not working, but there is a new error there :: Fatal error: Call to a member function sayhello() on boolean in C:\xampp\htdocs\php\magento\test.php the new code is $product = Mage::getModel('FirstStore_Demo/Product'); $product->sayhello(); Commented May 5, 2015 at 13:33
  • What version of PHP are you running and did you include any projects from Hackathon or Aitoc? Commented May 5, 2015 at 13:34

4 Answers 4

2

Magento does not yet support PHP 5.6 officially as the version you stated using in your comments. Please check the System Requirements page for supported software.

Especially in combination with XAMPP it might cause unexpected issues. I would advice you to downgrade to PHP 5.5.

2
0

Your model file, does not seem to extends the core class don't forget extends Mage_Core_Model_Abstract in the definition of your model class.. so it would be

class FirstStore_Demo_Model_Product extends Mage_Core_Model_Abstract
{
    public function sayhello(){
        echo 'Hello , World with Magento';
    }
}

Moreover you need to add your model declaration in your config.xml as someone wisely suggested

<models>

          <firststore_demo>
                   <class>FirstStore_Demo_Model</class>
          </firststore_demo>
</models>
0

Maybe you could solve this using routers, take a look to this question and its answer.

My first Hello World from a module and model and I can't load the model

-1

You ought to try

$productModel = Mage::getModel('firststore_demo/product');

And add to your config.xml

<models>

          <firststore_demo>
                   <class>FirstStore_Demo_Model</class>
          </firststore_demo>
</models>
6
  • Was suggested in the comments, didnt work :) Commented May 5, 2015 at 13:34
  • $productModel->sayhello();
    – Mick
    Commented May 5, 2015 at 13:35
  • Do you have some errors?
    – Mick
    Commented May 5, 2015 at 13:36
  • error : Fatal error: Call to a member function sayhello() on boolean in C:\xampp\htdocs\php\magento\test.php Commented May 5, 2015 at 13:39
  • what output - var_dump($productModel); ?
    – Mick
    Commented May 5, 2015 at 13:41

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.