重定向到错误的路径Phalcon

时间:2017-04-17 09:20:26

标签: php phalcon

刚开始使用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/

但是,当我输入时,我会得到enter image description here

因此,当我导航到localhost/bot/public/时,我得到了所需的输出。

为什么它的表现不像网站上给出的那样?

1 个答案:

答案 0 :(得分:2)

您在bot目录中需要.htaccess,它会将所有请求传递给public/index.php

类似的东西:

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

或类似的nginx配置。