cphalcon
cphalcon copied to clipboard
IndexController handler class cannot be loaded
I'm having trouble, when I open my browser for my phalcon project I keep getting this error: IndexController handler class cannot be loaded
Notice that I've tried two different version of the echo $app->handle line
app/controllers/IndexController.php
<?php
class IndexController extends \Phalcon\Mvc\Controller
{
public function indexAction()
{
echo "Hello World!";
}
}
?>
public/index.php
<?php
try{
// autoloader
$loader = new \Phalcon\Loader();
$loader->registerDirs([
'../app/controllers/',
'../app/models'
]);
$loader->register();
// dependency injection
$di = new \Phalcon\DI\FactoryDefault();
$di->set('view', function(){
$view = new \Phalcon\Mvc\View();
$view->setViewsDir('../app/views');
return $view;
});
// deploy the app
$app = new \Phalcon\Mvc\Application($di);
$request = new Phalcon\Http\Request();
// echo $app->handle($request->getURI())->getContent();
echo $app->handle($_GET['_url'] ?? '/')->getContent();
}
catch(\Phalcon\Exception $e){
echo $e->getMessage();
}
?>
Try this line
echo $this->app->handle($_SERVER['REQUEST_URI'])->getContent();
Try this line
echo $this->app->handle($_SERVER['REQUEST_URI'])->getContent();
I tried that and got this: Fatal error: Uncaught Error: Using $this when not in object context in /var/www/html/learning-phalcon/public/index.php:27 Stack trace: #0 {main} thrown in /var/www/html/learning-phalcon/public/index.php on line 27
Also took away 'this->' and replaced it with $app and left the rest of your app untouched but it went back to: LearningPhalconController handler class cannot be loaded
$response = $app->handle($_SERVER['REQUEST_URI']);
if (!$response->isSent()) {
$response->send();
}
and please also inject your route service and set the default module/contorller.
@garrett85 yes that should have been $app
apologies.
$loader->registerDirs([
'../app/controllers/',
'../app/models'
]);
This seems a bit suspicious. Is this the parent folder or where you are right now? ../app
or ./app
It might also be better to diagnose this if you set up a controller directory with namespaces and then use the loader to figure things out on its own. Just a thought
If you are using v5, enable debugging in your loader and print out the debug
information. That will give you more information on where the loader goes to find the files necessary
https://docs.phalcon.io/5.0/en/autoload#debugging
Please try to use v5 and if issue persists - reopen the issue. Closing.