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

"handler class cannot be loaded"

Ok, so first context. I am a COMPLETE Phalcon n00b. This is my first application, and actually my first time using MVC with PHP at all.

I'm running on CentOS, php version 5.3.3, apache 2.2.15.

I used the phalcon devtools to create my project structure:

$ find . 
. 
./app 
./app/forms 
./app/forms/PatientIntakeForm.php 
./app/cache 
./app/controllers 
./app/controllers/IndexController.php 
./app/controllers/ControllerBase.php 
./app/controllers/PatientintakeController.php 
./app/models 
./app/models/PatientIntake.php 
./app/models/AuditView.php 
./app/models/AuditValues.php 
./app/models/Users.php 
./app/models/AuditTransaction.php 
./app/views 
./app/views/layouts 
./app/views/PatientIntake 
./app/views/PatientIntake/search.volt 
./app/views/PatientIntake/edit.volt 
./app/views/PatientIntake/create.volt 
./app/views/PatientIntake/index.volt 
./app/views/index 
./app/views/index/index.volt 
./app/views/index.volt 
./app/config 
./app/config/loader.php 
./app/config/services.php 
./app/config/config.php 
./.htaccess 
./.phalcon 
./public 
./public/.htaccess 
./public/files 
./public/temp 
./public/index.php 
./public/js 
./public/img 
./public/css 
./index.html 

And all the stuff in app/config is the default except for me changing the MySQL credentials. I am more or less using Vokuro as an example/starting point. This is the beginning of my PatientintakeController.php:

<?php
namespace test\Controllers;

use Phalcon\Tag;
use Phalcon\Mvc\Controller;
use Phalcon\Mvc\Model\Criteria;
use Phalcon\Paginator\Adapter\Model as Paginator;
use test\Forms\PatientIntakeForm;
use test\Models\PatientIntake;

class PatientintakeController extends Controller {
}

When I try to go to https://URL.com/test/PatientIntake I get this "PatientintakeController handler class cannot be loaded"

What am I doing wrong? TIA!!



40.7k

Not sure why newlines aren't showing up when I paste from terminal, it makes reading the output of find rather difficult 0_o

So here is a pastebin: https://pastebin.com/BDj21Hp7

I see that you use namespaces in your project. Good practise but requires more configuration.

Open your /app/config/loader.php and add something like this:

$loader->registerNamespaces(
    array(
        'test\Controllers' => __DIR__ . '/../controllers/',
        'test\Models' => __DIR__ . '/../models/'
        /** and more if you need */
    ), 
    true
);
$loader->register();

Namespace does not change prefix in URL, so if you have test namespace and https://URL.com points to /app/public your controller should be available at https://URL.com/PatientIntake



40.7k

How do you get stuff inside the black box like that? here is what loader.php looks like now, still getting the error:

https://pastebin.com/rdXQv1pf

Owh. I remembered one more thing. You need set default namespace in Dispatcher.

$di->set('dispatcher', function() {
    $dispatcher = new Dispatcher();
    $dispatcher->setDefaultNamespace('test\Controllers');
    return $dispatcher;
});


2.2k

The black box is done using three backticks and the script type, like ```php, then add your code, and then close it with a final ```

// like this JS version
var name = "jim";
console.log(name);

or

// or this PHP version
$word = "this";
echo "like " . $word;

Check out the Help link to the upper right of the comment form for more fun.