简体   繁体   English

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

[英]Phalcon tutorial error PhalconException: TestController handler class cannot be loaded

I'm having some trouble getting Phalcon Tutorial 1 to work. 我在让Phalcon教程1正常工作时遇到了一些麻烦。 In the end I've cloned the version of it on Github to make sure I'm not missing something; 最后,我已经在Github上克隆了它的版本,以确保我没有丢失任何东西。 still getting the same behavior from that. 仍然从中得到相同的行为。

Pointing the browser to localhost/test as shown in the tutorial gives: ` 如本教程所示,将浏览器指向localhost / test可以得到:

"PhalconException: TestController handler class cannot be loaded".

Going to localhost/test.php , however, loads the "Hello!" 但是,转到localhost/test.php会加载“ Hello!”。 test message correctly. 正确测试消息。

Phalcon is shown in phpinfo() and get_loaded_extensions() . Phalcon显示在phpinfo() and get_loaded_extensions()

I get this behaviour even having cloned the tutorial from 即使从克隆了本教程,我也有这种现象

https://github.com/phalcon/tutorial . 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. 我的猜测是, apache无法正确重写URL,如Phalconphp路由中所述不起作用 ,但是我的问题似乎与那里的不一样。

Contents of htaccess files: htaccess文件的内容:

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

Replace in bootstrap file index.php 替换为引导文件index.php

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

with

$url->setBaseUri('/');

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. Phalcon教程似乎期望该教程在名为/ test /的目录中完成,而不是在Web根目录下完成。 It doesn't specify this, so I assumed /test would produce the behaviour shown in the tutorial with the project in web root. 它没有指定此名称,因此我假设/ test会在Web根目录中的项目中产生本教程中显示的行为。

You need change Dir of Controllers and Models if u run localhost/test.php 如果您运行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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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