本文介绍了Phalconphp路线不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的phalconphp,并跟随他们的教程,据我了解,我并不需要创建一个特定的路由组成部分,它应该拿起一个途径,如果它的存在。我显然是大规模错在这里,这意味着它应该很容易指正!但到目前为止,将工作的唯一控制器是我indexController的。

I'm new to phalconphp and following their tutorials, as far as I understand it, I don't need to create a specific routing component and that it should pick up a route if it exists. I could obviously be massively wrong here which means it should be easy to correct me! But so far the only controller that will work is my indexController.

这是我的引导

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

//Setting up the view component
$di->set('view', function(){
    $view = new \Phalcon\Mvc\View();
    $view->setViewsDir('../app/views/');
    return $view;
});

//Handle the request
$application = new \Phalcon\Mvc\Application($di);

echo $application->handle()->getContent();

} catch(\Phalcon\Exception $e) {
  echo "PhalconException: ", $e->getMessage();
}

然后,如果我创造我自己的FooController的

And then if I create my own FooController

<?php

class FooController extends \Phalcon\Mvc\Controller
{

public function indexAction()
{

    echo "FOO";

}

public function fooAction(){
    echo "FOO";
}

}

这些操作都不永远不会被解雇。现在,我居然收到来自服务器的404错误文件。所以,我不知道是否有一个问题,我的.htaccess文件,再次尽管这是从教程直接复制

Neither of these actions will ever get fired. Now I actually receive a 404 error document from the server. So I'm not sure if there's an issue with my .htaccess file, again though this is copied straight from the tutorial

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
   </IfModule>

任何人都可以看到什么明显错在这里?唯一的区别是我设置了为indexController的一个观点。我认为这是这是导致我相信这是更大的问题,与服务器404建立那么也许我的PHP code

Can anyone see anything obviously wrong here? The only difference is I've set up a view for the indexController. I think it's the 404 which is leading me to believe it's more an issue with the server set-up perhaps then my php code

推荐答案

您的.htaccess文件是罚款,不,你不需要任何路由文件,如果你只想使用标准的MVC /控制器/动作类型模式

Your .htaccess file is fine and, no, you don't need any routes file if you just want to use the standard MVC /controller/action type pattern.

您的问题是,您的HTTP服务器没有重新编写正确的URL。我不知道哪个HTTP服务器,你都在用,所以,我不能提供任何细节上固定的HTTP服务器本身。

Your issue is that your http server is not re-writing the URLs properly. I'm not sure which http server you are using, so, I can't provide any specifics on fixing the http server itself.

这篇关于Phalconphp路线不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 20:49