Phalcon教程错误PhalconException:无法加载TestController处理程序类

时间:2014-01-04 08:20:17

标签: php apache .htaccess phalcon

我在使Phalcon教程1工作时遇到了一些麻烦。最后我在Github克隆了它的版本,以确保我没有遗漏某些东西;仍然从那里获得相同的行为。

将浏览器指向localhost / test,如教程中所示:`

"PhalconException: TestController handler class cannot be loaded".

然后转到localhost/test.php,加载“你好!”正确测试消息。

Phalcon显示在phpinfo() and get_loaded_extensions()

即使从

克隆了教程,我也会遇到这种情况

https://github.com/phalcon/tutorial

我的猜测是apache没有正确重写网址,如 Phalconphp routes not working 所述,但我的问题似乎与那里的问题不一样

htaccess文件的内容:

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

#/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>

3 个答案:

答案 0 :(得分:7)

替换引导程序文件index.php

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

$url->setBaseUri('/');

答案 1 :(得分:2)

我的不好,这不是错误。 Phalcon教程似乎希望教程在名为/ test /的目录中完成,而不是在web根目录中完成。它没有指定这个,所以我假设/ test会产生教程中显示的行为与web根目录中的项目。

答案 2 :(得分:2)

如果您运行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();