We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

IndexController handler class cannot be loaded

Hello,

As I am trying to implement INVO to my basic phalcon app, I get this error when loading index.php:

IndexController handler class cannot be loaded

0 [internal function]: Phalcon\Mvc\Dispatcher->_throwDispatchException('IndexController...', 2)

1 [internal function]: Phalcon\Dispatcher->_dispatch()

2 [internal function]: Phalcon\Dispatcher->dispatch()

3 C:\xampp\htdocs\invocare\public\index.php(48): Phalcon\Mvc\Application->handle()

4 {main}



5.1k
edited Jul '17

see in your phpinfo if you have something like this

phalcon

Web framework delivered as a C-extension for PHP

phalcon enabled

Author Phalcon Team and contributors

Version 3.2.0

Build Date Jun 18 2017 19:00:50

Powered by Zephir Version 0.9.8-6335775f25



85.5k
edited Jul '17

loader problem.

make sure IndexController.php correctly named and correclty placed



4.2k
edited Jul '17

Here is my IndexController.php (which is placed in app/controllers):

<?php

class IndexController extends ControllerBase
{

    public function indexAction()
    {

         $this->view->title = "loool";
         $this->assets->addCss("css/mystyle.css");

    }

}

Actually I would like to be abble to debug this issue myself, if anyone has a methodology to do so I would like to know it. Thanks

Hi @Yotogeek this is all? you must include controllerbase on top

    use Phalcon\Mvc\Controller as ControllerBase;

Good luck



4.2k

Hello, I tried to include this line in IndexController.php but nothing change...



5.1k
edited Jul '17

One of the possible errors is that phalcon is not correctely installed, first check your phpinfo to see if you have phalcon lines also if it's ok I think it is in relation to your previous problem: something is wrong in your loader.php or in your index.php (boostrap file)

Hi @Yotogeek this is all? you must include controllerbase on top

   use Phalcon\Mvc\Controller as ControllerBase;

Good luck

No need if they are in the same folder but ControllerBase.php exist in app/controllers ?



85.5k

delete the file and create it again ( to make sure name is corect )

dump

$di->get("loader")



5.1k
edited Jul '17

Another of the possible errors is that BASE_PATH and APP_PATH is not correctly initilized

you can dump them for verify this point



4.2k
edited Jul '17

I would like to debug this issue using XDebug that I just installed on Sublime Text 3.

But I don't know where to put a breakpoint and what file to execute to target this specific problem.

Any idea ?

EDIT: I just realized that I had this error for every controller call, i.e if I load https://localhost/myapp or https://localhost/myapp/login or https://localhost/myapp/register



4.2k

@phil67000 Hello, thank you but I already installed XDebug, the problem is that I don't know how to use it to debug this specific problem.

In which file should I put a breakpoint ? What page should I load ?

To remember you, I got an "Controller" error for every page I load with a URI that normally calls a controller, i.e for https://localhost/myapp/ (IndexController handler class cannot be loaded), https://localhost/myapp/login (LoginController handler class cannot be loaded) etc.

If I find how to debug for this one then I will be abble to debug any other issue by myself. It would be cool that someone gives an example somewhere on "how to debug a Phalcon app using XDebug and Sublime Text 3).

Thanks



85.5k

i think you need to compile php with --debug and gdb aswell for those breakpoints

https://www.gnu.org/software/gdb/

the loader is in C code not php code



5.1k
edited Jul '17

@phil67000 Hello, thank you but I already installed XDebug, the problem is that I don't know how to use it to debug this specific problem.

In which file should I put a breakpoint ? What page should I load ?

The first link is just for vérify that you have the right version to suit your environment (just 5 minutes to be sûre and eliminate this possibility for possible future problems)

Have you read the second link ?

You have How to start XDEBUG and how to set breakpoint

XDEBUG site is also rich in informations

Just two tips :

Take the time to read the documentation, the tutorials before you start, it's saved time on debugging.

Follow the tutorials one by one in order and finish them. It's a good help to understand the mechanism of the framework.



4.2k
edited Jul '17

Ok, I have now Xdebug which correctly works (there was a bug with the "Launch browser" option not showing, you have to delete and recreate the .sublime-project file to solve this). I have put some breakpoints in several places of my app and started the debugging in Sublime, here is what I get:

As you can see the app stopped on the last breakpoint (at router.php), and there are some infos in Xdebug Stack section and Xdebug Context section.

But I don't know how to interpret those informations, any idea ?

Thanks



5.1k
edited Jul '17

sorry but i can't see C:\Users\MOI\Pictures\Screenshots\Xdebug.png

You have to store your pict on a public server in this case, You called index.php which to called router.php

The stack section give you the list of calls to arrive at this line

the context section give you all set variables Click on the name of a variable will give you at the bottom of the screen its content

xdebug extend also dumps, you can try var_dump($config); and see the resullt in your html page

edit it's good for the pict now



4.2k

Hi, thanks for this fast reply, but where should I put the var_dump($config); code ? I index.php ?



5.1k
edited Jul '17

anywhere after the declaration of the variable



4.2k

So I put var_dump($config); after $config = $di->getConfig(); in /public/index.php, here is what I get when I load index page:

C:\xampp\htdocs\invocare\public\index.php:45:
object(Phalcon\Config)[15]
  public 'database' => 
    object(Phalcon\Config)[38]
      public 'adapter' => string 'Mysql' (length=5)
      public 'host' => string 'localhost' (length=9)
      public 'username' => string 'root' (length=4)
      public 'password' => string '' (length=0)
      public 'dbname' => string 'volt' (length=4)
      public 'charset' => string 'utf8' (length=4)
  public 'application' => 
    object(Phalcon\Config)[39]
      public 'appDir' => string 'C:\xampp\htdocs\invocare/app/' (length=29)
      public 'controllersDir' => string 'C:\xampp\htdocs\invocare/app/controllers/' (length=41)
      public 'modelsDir' => string 'C:\xampp\htdocs\invocare/app/models/' (length=36)
      public 'migrationsDir' => string 'C:\xampp\htdocs\invocare/app/migrations/' (length=40)
      public 'viewsDir' => string 'C:\xampp\htdocs\invocare/app/views/' (length=35)
      public 'pluginsDir' => string 'C:\xampp\htdocs\invocare/app/plugins/' (length=37)
      public 'libraryDir' => string 'C:\xampp\htdocs\invocare/app/library/' (length=37)
      public 'cacheDir' => string 'C:\xampp\htdocs\invocare/cache/' (length=31)
      public 'formsDir' => string 'C:\xampp\htdocs\invocare/forms/' (length=31)
      public 'baseUri' => string '/invocare/' (length=10)

IndexController handler class cannot be loaded

#0 [internal function]: Phalcon\Mvc\Dispatcher->_throwDispatchException('IndexController...', 2)
#1 [internal function]: Phalcon\Dispatcher->_dispatch()
#2 [internal function]: Phalcon\Dispatcher->dispatch()
#3 C:\xampp\htdocs\invocare\public\index.php(57): Phalcon\Mvc\Application->handle()
#4 {main}


5.1k
edited Jul '17

well good progress

You already have the full path in the config, you use config.php file ?

Can you do same thing with $loader and post loader.php code



4.2k
edited Jul '17

@phil67000 yes I use config.php and the paths seems to be the good ones.

So, I added var_dump($loader); to the loader.php file, like this:

<?php

$loader = new Phalcon\Loader();

// We're a registering a set of directories taken from the configuration file
$loader->registerDirs(
[
APP_PATH . $config->application->controllersDir,
APP_PATH . $config->application->pluginsDir,
APP_PATH . $config->application->libraryDir,
APP_PATH . $config->application->modelsDir,
APP_PATH . $config->application->formsDir
]
);

var_dump($loader);

$loader->register();

And here is what I get when I load index:

C:\xampp\htdocs\invocare\app\config\loader.php:18: object(Phalcon\Loader)[36] protected '_eventsManager' => null protected '_foundPath' => null protected '_checkedPath' => null protected '_classes' => array (size=0) empty protected '_extensions' => array (size=1) 0 => string 'php' (length=3) protected '_namespaces' => array (size=0) empty protected '_directories' => array (size=5) 0 => string 'C:\xampp\htdocs\invocare/appC:\xampp\htdocs\invocare/app/controllers/' (length=69) 1 => string 'C:\xampp\htdocs\invocare/appC:\xampp\htdocs\invocare/app/plugins/' (length=65) 2 => string 'C:\xampp\htdocs\invocare/appC:\xampp\htdocs\invocare/app/library/' (length=65) 3 => string 'C:\xampp\htdocs\invocare/appC:\xampp\htdocs\invocare/app/models/' (length=64) 4 => string 'C:\xampp\htdocs\invocare/appC:\xampp\htdocs\invocare/forms/' (length=59) protected '_files' => array (size=0) empty protected '_registered' => boolean false

AppController handler class cannot be loaded

0 [internal function]: Phalcon\Mvc\Dispatcher->_throwDispatchException('AppController h...', 2)

1 [internal function]: Phalcon\Dispatcher->_dispatch()

2 [internal function]: Phalcon\Dispatcher->dispatch()

3 C:\xampp\htdocs\invocare\public\index.php(56): Phalcon\Mvc\Application->handle()

4 {main}

So, I see there is a problem with paths indeed. So, I removed the "APP_PATH " part, and I get this:

C:\xampp\htdocs\invocare\app\config\loader.php:18: object(Phalcon\Loader)[36] protected '_eventsManager' => null protected '_foundPath' => null protected '_checkedPath' => null protected '_classes' => array (size=0) empty protected '_extensions' => array (size=1) 0 => string 'php' (length=3) protected '_namespaces' => array (size=0) empty protected '_directories' => array (size=5) 0 => string 'C:\xampp\htdocs\invocare/app/controllers/' (length=41) 1 => string 'C:\xampp\htdocs\invocare/app/plugins/' (length=37) 2 => string 'C:\xampp\htdocs\invocare/app/library/' (length=37) 3 => string 'C:\xampp\htdocs\invocare/app/models/' (length=36) 4 => string 'C:\xampp\htdocs\invocare/forms/' (length=31) protected '_files' => array (size=0) empty protected '_registered' => boolean false

AppController handler class cannot be loaded

0 [internal function]: Phalcon\Mvc\Dispatcher->_throwDispatchException('AppController h...', 2)

1 [internal function]: Phalcon\Dispatcher->_dispatch()

2 [internal function]: Phalcon\Dispatcher->dispatch()

3 C:\xampp\htdocs\invocare\public\index.php(56): Phalcon\Mvc\Application->handle()

4 {main}

But still the same error in the end.

EDIT: I don't get why, the text goes so big at the end, sorry...



5.1k
edited Jul '17

Okay registered property is false because register is called after var_dump

C:\xampp\htdocs\invocare/forms/ : missing app/

missing this in loader.php https://github.com/phalcon/invo/blob/master/app/config/loader.php


$loader->registerClasses([
    'Services' => APP_PATH . 'app/Services.php'
]);

and Sevices.php init Dispatcher