2017-04-17 136 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的配置。