刚开始使用Phalcon,发现了一些奇怪的错误。
以下是public/index.php
<?php
use Phalcon\Loader;
use Phalcon\Mvc\View;
use Phalcon\Mvc\Application;
use Phalcon\Di\FactoryDefault;
use Phalcon\Mvc\Url as UrlProvider;
use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;
// Register an autoloader
$loader = new Loader();
$loader->registerDirs(
[
"../app/controllers/",
"../app/models/",
]
);
$loader->register();
// Create a DI
$di = new FactoryDefault();
// Setup the view component
$di->set(
"view",
function () {
$view = new View();
$view->setViewsDir("../app/views/");
return $view;
}
);
// Setup a base URI so that all generated URIs include the "bot" folder
$di->set(
'url',
function() {
$url = new \Phalcon\Mvc\Url();
$url->setBaseUri('/bot/');
return $url;
}
);
$application = new Application($di);
try {
// Handle the request
$response = $application->handle();
$response->send();
} catch (\Exception $e) {
echo "Exception: ", $e->getMessage();
}
根据这个,我的路径应该是localhost/bot/
。
因此,当我导航到localhost/bot/public/
时,我得到了所需的输出。
为什么它的表现不像网站上给出的那样?
答案 0 :(得分:2)
您在bot目录中需要.htaccess
,它会将所有请求传递给public/index.php
类似的东西:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule ((?s).*) public/$1 [L]
</IfModule>
或类似的nginx配置。