Phalcon tutorial error PhalconException: TestController handler class cannot be loaded

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-02 05:32:27

问题


I'm having some trouble getting Phalcon Tutorial 1 to work. In the end I've cloned the version of it onGithub to make sure I'm not missing something; still getting the same behavior from that.

Pointing the browser to localhost/test as shown in the tutorial gives: `

"PhalconException: TestController handler class cannot be loaded".

Going to localhost/test.php, however, loads the "Hello!" test message correctly.

Phalcon is shown in phpinfo() and get_loaded_extensions().

I get this behaviour even having cloned the tutorial from

https://github.com/phalcon/tutorial .

My guess is that apache is not re-writing URLs correctly, as described at Phalconphp routes not working , but my problem doesn't seem to the same as the one there.

Contents of htaccess files:

#/tutorial/.htaccess
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule  ^$ public/    [L]
    RewriteRule  (.*) public/$1 [L]
</IfModule>

and

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

回答1:


Replace in bootstrap file index.php

$url->setBaseUri('/tutorial/');

with

$url->setBaseUri('/');



回答2:


My bad, this isn't an error. The Phalcon tutorial seems to expect that the tutorial is being completed in a directory called /test/, not web root. It doesn't specify this, so I assumed /test would produce the behaviour shown in the tutorial with the project in web root.




回答3:


You need change Dir of Controllers and Models if u run localhost/test.php

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

//Create a DI
$di = new Phalcon\DI\FactoryDefault();

//Setup the view component
$di->set('view', function(){
    $view = new \Phalcon\Mvc\View();
    $view->setViewsDir('app/views/');
    return $view;
});

//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;
});

//Handle the request
$application = new \Phalcon\Mvc\Application($di);
echo $application->handle()->getContent();


来源:https://stackoverflow.com/questions/20918648/phalcon-tutorial-error-phalconexception-testcontroller-handler-class-cannot-be

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!