简体   繁体   中英

PhalconException: NameController handler class cannot be loaded

Tried with the question but it didn't fix my issue. : Phalcon tutorial error PhalconException: TestController handler class cannot be loaded

My application is in AWS ubuntu 14.0 and some pages are working fine but for few pages, I'm getting this error:

PhalconException: NameController handler class cannot be loaded.

My controller names are CamelCase!

//Setup a base URI so that all generated URIs include the "tutorial" folder
$di->set('url', function(){
    $url = new \Phalcon\Mvc\Url();
    $url->setBaseUri('/');
    return $url;
});

I changed my apache2.conf file to AllowOverride: all :

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride all
    Require all granted
</Directory>

My App is here projectname/admin/app/ :

try {
    //Register an autoloader
    $loader = new \Phalcon\Loader();
    $loader->registerDirs(array(
        '../app/controllers/',
        '../app/models/',
        '../app/plugins/',
    ))->register();

cant able to debug this can anyone help what else could be the issue.?

如果控制器中不存在控制器页面,则会出现此问题,因此请重新检查控制器页面是否存在。

这只是意味着这样的控制器不存在,就像没有加载类一样。

I was getting this error so i fixed it in public/index.php

  • Find the line echo $application->handle($_SERVER['REQUEST_URI'])->getContent() or echo $application->handle()->getContent() or code related to this.
  • The main error is request_uri which is redirected to wrong controller
  • for example if you try to echo $_SERVER['REQUEST_URI'] , it will also show the domain name.
  • so i fixed it locally like this. Replace this whole line with following code
 $request_uri=str_replace(["\n","\r","\t"], '', $_SERVER['HTTP_HOST']); if($request_uri=='localhost'){ $url=explode('/',$_SERVER['REQUEST_URI']); array_shift($url); array_shift($url); $url=implode('/',$url); $url='/'.$url; } else $url=$request_uri; echo $application->handle($url)->getContent();

OR Simply use /{controller name}/{function name} in handle function

  • The main error was that it was redirecting to domain named controller because of $_SERVER['REQUEST_URI'] but we have to ignore domain name and redirect it to controller name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM