Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controller file was loaded but class does not exist

Tags:

magento

I am having trouble getting around this error in Magento:

"Controller file was loaded but class does not exist". (Full stack at bottom)

I am essentially trying to follow this tutorial: Create new module “HelloWorld” – in Magento.

...though I am using my own company/class names etc. instead of "hello world"

I am having trouble finding good documentation on Magento in general, and I am very new at it...

can anyone provide some common causes, advice, or insight? I am swamped, googled this for hours, check permissions and file structure. You name it.

Trace:
#0 /var/www/dev/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(306): Mage::exception('Mage_Core', 'Controller file...')
#1 /var/www/dev/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(282): Mage_Core_Controller_Varien_Router_Standard->_inludeControllerClass('/var/www/dev_ml...', 'Foo_Wr...')
#2 /var/www/dev/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(195): Mage_Core_Controller_Varien_Router_Standard->_validateControllerClassName('foo_Wr...', 'index')
#3 /var/www/dev/app/code/core/Mage/Core/Controller/Varien/Front.php(158): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#4 /var/www/dev/app/Mage.php(459): Mage_Core_Controller_Varien_Front->dispatch()
#5 /var/www/dev/index.php(65): Mage::run()
#6 {main}
like image 532
frank Avatar asked Feb 04 '10 19:02

frank


4 Answers

That error means that magento found a file for your controller where it expected to (app/code/local/Namespace/Module/controllers/FooController.php) but that the class inside didn't have the name it expected (it wasn't Namespace_Module_FooController).

like image 141
Greg Avatar answered Nov 19 '22 22:11

Greg


Hope you got this sorted, just to let you know I looked at the same tutorial, and I think this error may be fixed by the addition of the <?php declaration to the start of the php code samples.

like image 31
Simon Avatar answered Nov 19 '22 21:11

Simon


You might find this article, (part of a larger series) (self-link) more helpful, and it goes more into the why of what you're doing, which will enable you to better debug things yourself in the future.

As for your specific error

Controller file was loaded but class does not exist

This means magento was able to correctly require/include the file you placed your controller in but the controller class was misnamed. Controllers should be named

Packagename_Module_ControllernameController

and located in the folder

app/code/local/Packagename/Modulename/controllers/ControllernameController.php
like image 42
Alan Storm Avatar answered Nov 19 '22 21:11

Alan Storm


I was getting this error because I was using following code in my CartController(Overridden)

require_once "Mage/Checkout/controllers/CartController.php"; 
class Muk_Mycart_CartController extends Mage_Core_Controller_Front_Action
{
}

instead of following code of line

require_once "Mage/Checkout/controllers/CartController.php"; 
class Muk_Mycart_Checkout_CartController extends Mage_Core_Controller_Front_Action
{
}

I was missing "Checkout" in "Muk_Mycart_CartController".This is error because I was using following code in my CartController(Overridden)

My directory structure was like this

\app\code\local\Muk\Mycart\controllers\Checkout
\app\code\local\Muk\Mycart\controllers\Checkout\CartController.php
like image 31
Mukesh Avatar answered Nov 19 '22 21:11

Mukesh