简体   繁体   中英

Phalcon tutorial error PhalconException: TestController handler class cannot be loaded

I'm having some trouble getting Phalcon Tutorial 1 to work. In the end I've cloned the version of it on Github 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>

Replace in bootstrap file 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. It doesn't specify this, so I assumed /test would produce the behaviour shown in the tutorial with the project in web root.

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();

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