1

I'm following a video tutorial on Magento for developers and I'm quite a beginner at this. I'm currently using Magento CE 1.9.2.4.

I created a simple dummy module which controller works fine. Although, when I add a model and try to get its class, the controller action I use to get_class just gives no result (empty page). If I add an echo before that line I can see the message correctly.

Things I've tried so far:

  • checked other similar Q&A but I don't seem to have made the same mistakes
  • reset all files chmods to 664 and all folders to 755
  • reset all chowns to the standard user:group
  • disable and re-enable module output from the Admin > System > Configuration > Advanced section
  • re-watched the tutorial steps over and over

I'm out of options now. Seeing the controller working (index and phpinfo actions work fine) it seems like there's a problem in the model itself but I can't find it.

Any help will be greatly appreciated!

EDIT 1

After roughly an hour of checking around for a solution I just refreshed the page and it worked.

This raises even more questions because since I started developing days ago I immediately disabled then purged all caches in the admin and also tried opening the page in browser's private mode many many times with no success.

So it seems like there's something else caching the page, not magento nor my browser. What could it be?

END OF EDIT 1

Some details to follow.

Module tree structure:

Module tree

./etc/modules/Disc_Prova.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!-- app/etc/modules/Disc_Prova.xml -->
<config>
    <modules>
        <Disc_Prova>
            <active>true</active>
            <codePool>local</codePool>
        </Disc_Prova>
    </modules>
</config>

./app/code/local/Disc/Prova/etc/config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!-- app/code/local/Disc/Prova/etc/config.xml -->
<config>

    <global>
        <blocks>
            <Disc_Prova>
                <class>Disc_Prova_Block</class>
            </Disc_Prova>
        </blocks>
        <helpers>
            <Disc_Prova>
                <class>Disc_Prova_Helper</class>
            </Disc_Prova>
        </helpers>
        <models>
            <Disc_Prova>
                <class>Disc_Prova_Model</class>
            </Disc_Prova>
        </models>
    </global>

    <frontend>
        <routers>
            <disc_prova>
                <use>standard</use>
                <args>
                    <module>Disc_Prova</module>
                    <frontName>prova</frontName>
                </args>
            </disc_prova>
        </routers>
    </frontend>

</config>

./app/code/local/Disc/Prova/controllers/IndexController.php:

<?php

class Disc_Prova_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
        echo 'Works!';
    }

    public function modelAction()
    {
        // Adding this line shows the text correctly
        //echo "blabla1";
        echo get_class(Mage::getModel('Disc_Prova/Roba'));
        // Adding this line shows the text correctly
        //echo "blabla2";
    }

    public function phpinfoAction()
    {
        phpinfo();
    }
}

./app/code/local/Disc/Prova/Model/Roba.php:

<?php
// app/code/local/Disc/Prova/Model/Roba.php

class Disc_Prova_Model_Roba extends Mage_Core_Model_Abstract 
{

}

Result with commented echo(s):

result no echo

Result with uncommented echo(s):

enter image description here

EDIT 2

I created a new module, Atest_Module:

enter image description here

./app/etc/modules/Atest_Module.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <atest_module>
            <active>true</active>
            <codePool>local</codePool>
        </atest_module>
    </modules>
</config>

./app/code/local/Atest/Module/etc/config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- app/code/local/Atest/Module/etc/config.xml -->
<config>

    <global>
        <blocks>
            <atest_module>
                <class>Atest_Module_Block</class>
            </atest_module>
        </blocks>
        <helpers>
            <atest_module>
                <class>Atest_Module_Helper</class>
            </atest_module>
        </helpers>
        <models>
            <atest_module>
                <class>Atest_Module_Model</class>
            </atest_module>
        </models>
    </global>

    <frontend>
        <routers>
            <atest_module>
                <use>standard</use>
                <args>
                    <module>Atest_Module</module>
                    <frontName>atest</frontName>
                </args>
            </atest_module>
        </routers>
    </frontend>

</config>

./app/code/local/Atest/Module/controllers/IndexController.php

class Atest_Module_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
        echo 'Works!';
    }

    public function modelAction()
    {
        // Adding this line shows the text correctly
        //echo "blabla1";
        echo get_class(Mage::getModel('atest_module/roba'));
        // Adding this line shows the text correctly
        //echo "blabla2";
    }

    public function phpinfoAction()
    {
        phpinfo();
    }
}

./app/code/local/Atest/Module/Model/Roba.php

<?php

class Atest_Module_Model_Roba extends Mage_Core_Model_Abstract 
{

}

Now the controller isn't even hit. I bet if I try in an hour it will work..?

enter image description here

END OF EDIT 2

EDIT 3

After changing the module declaration in /app/etc/modules/Atest_Module.xml to Capitalized, the module works immediately. So at the end, apart from the upper/lower case mishap, I think deleting var/cache made the module appear immediately.

END OF EDIT 3

  • Have you tried like below $obj = Mage::getModel('Disc_Prova/Roba'); echo get_class($obj); – shabbir Aug 17 '16 at 8:57
  • Same result, blank page. – GigiSan Aug 17 '16 at 9:06
  • 1
    i test ur code i can't find problem with that is showing this out Disc_Prova_Model_Roba on url prova/index/model make sure you clear ur cache or disabled it – Qaisar Satti Aug 17 '16 at 9:12
  • 1
    @GigiSan fschmengler's answer is correct you must use the lower case so it's not look weird but using in upper case can't create problem. it will work with both. – Qaisar Satti Aug 17 '16 at 9:43
  • 1
    after seeing this you have added the lower case where upper needed kindly compare with my answer and then you will find your mistakes – Qaisar Satti Aug 17 '16 at 10:26
1

your module configuration

  <?xml version="1.0" encoding="UTF-8"?>
<!-- app/etc/modules/Disc_Prova.xml -->
<config>
    <modules>
        <Disc_Prova>
            <active>true</active>
            <codePool>local</codePool>
        </Disc_Prova>
    </modules>
</config>

your config.xml with changes you have to do

<?xml version="1.0" encoding="UTF-8"?>
<!-- app/code/local/Disc/Prova/etc/config.xml -->
<config>
    <modules>
        <Disc_Prova>
            <version>0.1.0</version>
        </Disc_Prova>
    </modules>
    <global>
        <blocks>
            <disc_prova>
                <class>Disc_Prova_Block</class>
            </disc_prova>
        </blocks>
        <helpers>
            <disc_prova>
                <class>Disc_Prova_Helper</class>
            </disc_prova>
        </helpers>
        <models>
            <disc_prova>
                <class>Disc_Prova_Model</class>
            </disc_prova>
        </models>
    </global>

    <frontend>
        <routers>
            <disc_prova>
                <use>standard</use>
                <args>
                    <module>Disc_Prova</module>
                    <frontName>prova</frontName>
                </args>
            </disc_prova>
        </routers>
    </frontend>

</config>

your controller

    <?php

class Disc_Prova_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
        echo 'Works!';
    }

    public function modelAction()
    {
        // Adding this line shows the text correctly
        //echo "blabla1";
        echo get_class(Mage::getModel('disc_prova/roba'));
        // Adding this line shows the text correctly
        //echo "blabla2";
    }

    public function phpinfoAction()
    {
        phpinfo();
    }
}

you model

 <?php
// app/code/local/Disc/Prova/Model/Roba.php

class Disc_Prova_Model_Roba extends Mage_Core_Model_Abstract 
{

}

At the end delete cache folder in var/cache

2

It should be Mage::getModel('Disc‌​_Prova/roba');

Explanation:

the first part (Disc_Prova) is the alias you defined in config.xml:

<models>
    <Disc_Prova>                           <---- HERE
        <class>Disc_Prova_Model</class>
    </Disc_Prova>
</models>

the second part (roba) is what follows after the prefix

<models>
    <Disc_Prova>
        <class>Disc_Prova_Model</class> <--- PREFIX
    </Disc_Prova>
</models>

but in lower case!

This looks less weird if you follow the convention to make the module aliases lower case as well:

    <models>
        <disc_prova>
            <class>Disc_Prova_Model</class>
        </disc_prova>
    </models>

Then it's Mage::getModel('disc_prova/roba')

  • I have doubts about this answer, both because the tutorial shows capitalized XML tags (and its demo works) and because this should have never worked (see edit 1). I will try to develop a brand new module following your convention to see if it works straight away. If it doesn't I'll try delete var/cache as suggested in the question's comments. Thanks for your time nonetheless. – GigiSan Aug 17 '16 at 9:37
  • 1
    You're right, it is non-standard but will still work because when Magento transforms it to CamelCase, the class name is correct. I overlooked the fact that it suddenly worked. – Fabian Schmengler Aug 17 '16 at 9:43
  • I think that is not causing the problem.. – Qaisar Satti Aug 17 '16 at 9:45
  • 2
    Still, I would not trust a beginners tutorial that does not follow basic naming conventions – Fabian Schmengler Aug 17 '16 at 9:47
  • Shush! We're talking about the official "Fundamentals of Magento Development" course! :D I'm joking... I find it quite slippery in some points too, and I know nothing about the subject :P – GigiSan Aug 17 '16 at 9:58
0

I'm posting this answer for completion. The main problem that caused me to ask this question was due to the presence of a cached version in <magento root>/var/cache. Deleting that folder solved the problem.

There were some upper/lower case mishaps in the middle but they were not causing the original problem.

Thanks to @Qaisar Satti and @fschmengler for their precious help!

EDIT:

After applying all the suggestion in the other answers, I was still repeatedly having caching problems in the order of minutes for every single page. Investigating further I found that the very core of the problem was that the PHP module OPcache was enabled on my web server.

I disabled it by editing php.ini by replacing

opcache.enable=1

with

opcache.enable=0

Now, after days of torment, I can finally hit that F5 with serenity. What a relief.

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.