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

MyApp\Controllers\Admin\UsersController handler class cannot be loaded

I've been working on the MVC example from the official repository mvc/simple-subcontrollers for sometimes, It's from https://github.com/phalcon/mvc/tree/master/simple-subcontrollers

My environment: ubuntu 14.04, apache2 php5.5 phalcon2.0.8

Dir Structure:

/wwwroot/
    app
    public

It's just the same structure of the offical repository of mvc/simple-subcontrollers

The configure of apache2

Alias /abcd "/var/wwwroot/public"
<Directory "/var/wwwroot/public">
                Options FollowSymLinks
               AllowOverride All
               Order allow,deny
                Allow from all
</Directory>

The .htaccess file under public

AddDefaultCharset UTF-8

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /abcd/
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>

And I didn't modify any code of it except some of baseUri to "/abcd/"

When I visit the page: https://localhost/abcd/users, It works well!

But when I try to visit the admin page: https://localhost/abcd/admin/users, It just says:

MyApp\Controllers\Admin\UsersController handler class cannot be loaded

How to correct it?



85.5k
Accepted
answer
edited Oct '15

well do you have this controller properly defined ?

Since this is working, your apache config seems to be fine.

Now this error is triggered by Router. So Can you post your router and I will try explain a bit

edit:

sorry i didnt notice you are using those examples.

can you change the "Admin" to "admin" in routers and controller namespaces

btw i tried some of those examples and it didn't work for me aswell. I use this one, cuz it seems to be only 1 working well ( only few fatal errors on startup but it's jsut changing a function name, and adding a param inside a function )

https://github.com/michaelkrone/generator-phalcon



31.3k
edited Oct '15

Many Thanks!

Change the Admin to admin in routers and controller namespaces can work!

OR change the admin dir to Admin also can work!

....Is it a bug of Phalcon 2.0.8?

and BTW, if I create the IndexController under the controllers dir and the controllers/Admin dir

  1. https://localhost/abcd/ can work,

  2. https://localhost/abcd/admin can't work, says: MyApp\Controllers\AdminController handler class cannot be loaded

  3. https://localhost/abcd/admin/ can work, but it seem to be the same to https://localhost/abcd/

4 .https://localhost/abcd/admin/index can work, It's the real backend.

why? The 3 is not the same to the 4?

well do you have this controller properly defined ?

Since this is working, your apache config seems to be fine.

Now this error is triggered by Router. So Can you post your router and I will try explain a bit

edit:

sorry i didnt notice you are using those examples.

can you change the "Admin" to "admin" in routers and controller namespaces

btw i tried some of those examples and it didn't work for me aswell. I use this one, cuz it seems to be only 1 working well ( only few fatal errors on startup but it's jsut changing a function name, and adding a param inside a function )

https://github.com/michaelkrone/generator-phalcon



85.5k

because of this in your router :

$router->add('/:controller', array(
    'namespace' => 'MyApp\Controllers',
    'controller' => 1
));

it means that if you have 1 parameter after abcd will look for that controller, so basiccaly if you want this https://localhost/abcd/admin to work you have to have AdminController inside controllers folder.

I for example set my default controller and action to be index.

Take a look at this documentation:

https://docs.phalcon.io/en/latest/reference/routing.html#setting-default-paths

You have to understand the routes, its very important. It's not hard, it will just take you few days and tests in order for you to get use to the logic. I tihink it took me a week until i start modifing the content inside a ready application.

Cheers



31.3k

Thank you very much! It's really the key point

because of this in your router :

$router->add('/:controller', array(
  'namespace' => 'MyApp\Controllers',
  'controller' => 1
));

it means that if you have 1 parameter after abcd will look for that controller, so basiccaly if you want this https://localhost/abcd/admin to work you have to have AdminController inside controllers folder.

I for example set my default controller and action to be index.

Take a look at this documentation:

https://docs.phalcon.io/en/latest/reference/routing.html#setting-default-paths

You have to understand the routes, its very important. It's not hard, it will just take you few days and tests in order for you to get use to the logic. I tihink it took me a week until i start modifing the content inside a ready application.

Cheers