Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swoft2.0 restful路由中文字符问题 #678

Closed
geekchenzx opened this issue Jun 1, 2019 · 5 comments
Closed

swoft2.0 restful路由中文字符问题 #678

geekchenzx opened this issue Jun 1, 2019 · 5 comments
Assignees
Labels
unconfirmed waiting for confirmation

Comments

@geekchenzx
Copy link

中文字符通过restful get方法,框架接收到的字符确实框架自动转换成某个字母,或者出现报错路由未定义

@geekchenzx
Copy link
Author

PHP版本7.3 ,swoole版本 4.3.3,OS: macOS

@inhere inhere added the unconfirmed waiting for confirmation label Jun 1, 2019
@inhere
Copy link
Member

inhere commented Jun 1, 2019

提供一个可复现的demo代码

@geekchenzx
Copy link
Author

提供一个可复现的演示代码

/**
* 搜索某个资源
* @RequestMapping(route="search/{name}", method={RequestMethod::GET})
* @param Request $request
* @param string $name
* @return array
*/
public function search(Request $request, string $name)
{
try {
$data = $this->resource->search($name);

        if (!$data->toArray()) {
            return res_data(0, '暂无搜索内容');
        }
        return res_data(1, 'success', $data);
    }catch (\Exception $e) {
        return res_data(0, '数据库出错: ' . $e->getMessage());
    }
}

public function search(string $field): object
{
return Resource::where('name', 'like', "%{$field}%")->get();

}

如果name值为中文就会出现上诉问题 postman测试会出现这个问题

@inhere
Copy link
Member

inhere commented Jun 5, 2019

我在单元测试里测试 是没有问题的呢

@inhere inhere self-assigned this Jun 5, 2019
@panyongwei
Copy link
Contributor

提供一个可复现的演示代码

/**

  • 搜索某个资源
  • @RequestMapping(route="search/{name}", method={RequestMethod::GET})
  • @param Request $request
  • @param string $name
  • @return array
    */
    public function search(Request $request, string $name)
    {
    try {
    $data = $this->resource->search($name);
        if (!$data->toArray()) {
            return res_data(0, '暂无搜索内容');
        }
        return res_data(1, 'success', $data);
    }catch (\Exception $e) {
        return res_data(0, '数据库出错: ' . $e->getMessage());
    }
}

public function search(string $field): object
{
return Resource::where('name', 'like', "%{$field}%")->get();

}

如果name值为中文就会出现上诉问题 postman测试会出现这个问题

image
这边按照这样操作也是没有问题的

@stelin stelin closed this as completed Jul 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unconfirmed waiting for confirmation
Projects
None yet
Development

No branches or pull requests

4 participants