我创建了一个用于搜索用户的函数。但。。。。我需要在名称之间用空格搜索它。
例如,搜索"John Doe":
我的网址应该是:
https://localhost/cp/admin/users/get/John 多伊
我不知道该怎么做,但是,我得到空响应,因为他无法识别空格。
代码(我不知道这会有什么帮助,但没关系。
public function get($username) {
$res = $this->db->where("username", $username)->get("users");
$res = array("user" => $res->row());
echo json_encode($res, JSON_UNESCAPED_UNICODE);
}
你不能像这样传递 url 参数。
在追加到 url 之前,您需要urlencode()
并在控制器中urldecode()
。
urlencode()
将所有非安全字符替换为安全字符。 urldecode
做的恰恰相反。
例如,解码后,John Doe
在 url 中变为John+Doe
,在控制器中变为John Doe
。