2017-04-17 164 views
0

刚开始使用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/,我得到所需的输出。

为什么它不像网站上给出的方式?

回答

2

您需要BOT目录.htaccess将通过所有请求public/index.php

喜欢的东西:

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

或者类似nginx的配置。