Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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: “http://standard.zhaobing/search/内建”, matched router is null , while "http://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;



4.6k
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());
    }
    ... ...


4.6k
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']);
... ...