We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Is this a router's bug?(urls, including chinese words, could not been parsed!)

In router file, I set the route as follow,

$router->add('/search/{search:[^/]+}','standards::search')->setName('standards.search.index');

yet when I navigate to url: “https://standard.zhaobing/search/内建”, matched router is null , while "https://standard.zhaobing/search/架构" is OK, and searchs for english words are OK too.

Can anyone give a tip?

I'm using WAMP 64bit, php5.6.16 64bit; phalcon 2.1.0b;



7.0k
Accepted
answer
edited Feb '16

Have fixed this bug! need urldecode($request->getURI())

$eventsManager = new \Phalcon\Events\Manager();
$eventsManager->attach("dispatch:beforeDispatchLoop", function($event, \Phalcon\Mvc\Dispatcher $dispatcher){

    $router = \Phalcon\Di::getDefault()->get('router');
    $route=$router->getMatchedRoute();
    if(null == $route) {
        $request = new \Phalcon\Http\Request();
        $router->handle(urldecode($request->getURI()));//这里需要特殊关注一下,也许将来在框架中能够得到修正
        $route = $router->getMatchedRoute();
        if(null == $route) die('url地址无效,找不到对应的路由设置!');

        $dispatcher->setControllerName($router->getControllerName());
        $dispatcher->setActionName($router->getActionName());
        $dispatcher->setParams($router->getParams());
    }
    ... ...


7.0k
edited Feb '16

Found another solution, in router file:

use Phalcon\Mvc\Router;
$router = new myRouter(false);
$router->setUriSource(Router::URI_SOURCE_SERVER_REQUEST_URI); // Use $_SERVER['REQUEST_URI'] 
$_SERVER['REQUEST_URI'] = urldecode($_SERVER['REQUEST_URI']);
... ...