1

I am just learning Magento from the book Magento for PHP Devs but when I tried to recreate this code I got an error: PHP warning: include(Mage/Mdg/Giftregistry/Model/Entity.php): failed to open stream: No such file or directory in /var/www/html/learn/lib/Varien/Autoload.php on line 94

Due I have no experience I require some help. I have flushed Cache several times and still don't get it right. This is some data.

The error happens when I try to create a new model: $registry = Mage::getModel('mdg_giftregistry/entity');

ERROR: PHP warning: include(Mage/Mdg/Giftregistry/Model/Entity.php): failed to open stream: No such file or directory in /var/www/html/learn/lib/Varien/Autoload.php on line 94

Im using magerun netz98. Maybe this has something to do?

My files:

app/etc/modules/Mdg_Giftregistry.xml

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

app/code/local/Mdg/Giftregistry/etc/config.xml:

    <?xml version="1.0"?>
<config>
    <modules>
        <Mdg_Giftregistry>
            <version>0.2.0</version>
        </Mdg_Giftregistry>
    </modules>
    <global>
        <models>
            <mdg_giftregistry>
                <class>Mdg_Giftregistry_Model</class>
            </mdg_giftregistry>
        </models>
        <blocks>
            <mdg_giftregistry>
                <class>Mdg_Giftregistry_Block</class>
            </mdg_giftregistry>
        </blocks>
        <helpers>
            <mdg_giftregistry>
                <class>Mdg_Giftregistry_Helper</class>
            </mdg_giftregistry>
        </helpers>
        <resources>
            <mdg_giftregistry_setup>
                <setup>
                    <module>Mdg_Giftregistry</module>
                </setup>
            </mdg_giftregistry_setup>
        </resources>
    </global>
</config>

app/code/local/Mdg/Giftregistry/Model/Entity.php :

    <?php
    class Mdg_Giftregistry_Model_Entity extends Mage_Core_Model_Abstract {
      public function __construct() {
      $this->_init('mdg_giftregistry/entity');
      parent::_construct();
     }
    }

Any suggestion?

  • May you have enable s magento compiler – Amit Bera Oct 2 '15 at 9:58
3

There are a couple of different ways this can happen. I got stuck at the same place while working on the book.

If you take a look at the Alan Storm tutorials on Magento Development there is a part in the models section where he directs you to get this very same error. After creating the controller page and setting up $blogpost = Mage::getModel('weblog/blogpost'); in the controller, you refresh the page and error out. He states, "Magento is trying to __autoload include this Model, but can't find the file". In that tutorial, you haven't made the Blogpost.php file yet, so there is no file to find.

What this means for us can be a few different things. Misspeling would be the first thing to check. For me, I had misspelled Mdg_Giftregistry.xml as Mgd_Giftregistry.xml. It's really easy to do, and it's a tricky to track down because the module will load in the backend of Magento (System -> Config -> Advanced -> Advanced) but all your other files will not be seen, and therefor will never find the correct path to your model.

One de-bug clue that you have in the code is the very sneaky part of the warning: ..include(Mage/Mdg/..

You can see that Magento is trying to load Mage/Mdg/Giftregistry/Model/Entity.php and not Mdg/Giftregistry/Model/Entity.php. This means that Magento went looking in the spot it thought you had the file by taking apart the call Mage::getModel('mdg_giftregistry/entity'); into the URI Mdg/Giftregistry/Model/Entity.php and when it didn't find the file there, it looked into the Mage folder to see if it could find the model there. When that didn't happen it errors out.

Another issue (while less likely) could be file permissions. If Magento can't read the file, this is the error it would kick. Check that you have correct ownership and file permissions are correct.

The last possibility is an error with the dev:console itself. This is easy to check though, if the first line of code the book instructs you to use $customer = Mage::getModel('customer/customer')->load(1); works, then the console is fine and the issue is in the code.

1

come first parent::_construct();

<?php
        class Mdg_Giftregistry_Model_Entity extends Mage_Core_Model_Abstract {
          public function __construct() {
          parent::_construct();
          $this->_init('mdg_giftregistry/entity');

         }
        }
  • I've tried moving around the parent::_construct() in this case, but it's still not resolving the error for me. I think the root of the problem is that the model is being seen as Mage/Mdg/Giftregistry/Model/Entity.php instead of Mdg/Giftregistry/Model/Entity.php. Any ideas on what it might be? – circlesix Jul 30 '16 at 4:05
1

Pretty sure it's caused by the fact that no resource models are declared nor database table in your module config.

You need to add the following in the <models> tag:

<resourceModel>mdg_giftregistry_mysql4</resourceModel>

Then in your <global> tag you can add:

        <mdg_giftregistry_mysql4>
            <entities>
                <mdg_giftregistry>
                    <entity>[entity_table_name]</entity>
                </mdg_giftregistry>
            </entities>
        </mdg_giftregistry_mysql4>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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