【问题标题】:Phalcon routingPhalcon路由
【发布时间】:2017-08-18 10:04:34
【问题描述】:

你好,对不起我的英语。

我的网站结构:

https://site.ru/category_1/.../category_N/post.html

routes.php:

$router = new Phalcon\Mvc\Router();

$router->notFound(array(
    'controller' => 'index',
    'action' => 'error404',
));

$router->add(
    '/', array(
        'controller' => 'index',
        'action' => 'index'
    )
);

$router->add(
    '/{uri:[a-zA-Z0-9\-\/\.]+}', array(
        'controller' => 'index',
        'action' => 'index',
    )
);

$router->add(
    '/sitemapsyswrub7g5ox6mtz2tbplwiu6yduox6m.xml', array(
        'controller' => 'index',
        'action' => 'sitemap'
    )
);

return $router;

1) 首先查看site.ru/sitemapsyswrub7g5ox6mtz2tbplwiu6yduox6m.xml

2) 下一个检查帖子。

Uri 转移到控制器/动作。

控制器查看 $uri 并加载帖子。

3) 然后检查主页。 site.ru/index.php、site.ru/index.html 和 site.ru/index.htm 在 htaccess 文件中重定向到 site.ru 它有效。 但我有问题。如果网址:

site.ru/blabla_

然后 phalcon 显示错误:

BlablaController handler class cannot be loaded

#0 [internal function]: Phalcon\Mvc\Dispatcher->_throwDispatchException('BlablaControlle...', 2)
#1 [internal function]: Phalcon\Dispatcher->_dispatch()
#2 [internal function]: Phalcon\Dispatcher->dispatch()
#3 /home/srv/http/project/site.ru/public/index.php(23): Phalcon\Mvc\Application->handle()
#4 {main}

如果网址:

site.ru/blabla_.

然后好的,工作错误404。

帮助为 error404 制定正确的路由。

【问题讨论】:

    标签: php routing phalcon


    【解决方案1】:

    url "sitemapsyswrub7g5ox6mtz2tbplwiu6yduox6m.xml" 匹配 {uri:[a-zA-Z0-9-/.]+}

    将 uri:[a-zA-Z0-9-/.]+} 移动到最终文件路由规则中

    例子

    $router = new Phalcon\Mvc\Router();
    
    $router->notFound(array(
        'controller' => 'index',
        'action' => 'error404',
    ));
    
    $router->add(
        '/sitemapsyswrub7g5ox6mtz2tbplwiu6yduox6m.xml', array(
            'controller' => 'index',
            'action' => 'sitemap'
        )
    );
    
    $router->add(
        '/{uri:[a-zA-Z0-9\-\/\.]+}', array(
            'controller' => 'index',
            'action' => 'index',
        )
    );
    
    $router->add(
        '/', array(
            'controller' => 'index',
            'action' => 'index'
        )
    );
    
    return $router;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-07
      • 1970-01-01
      • 2013-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多