gpt4 book ai didi

php - 带有 $id 的路由或 Codeigniter 中的所有数据

转载 作者:行者123 更新时间:2023-11-29 09:32:33 25 4
gpt4 key购买 nike

我想获取所有数据或通过 id 选择,但出了问题。当我尝试使用路线时,不起作用。如果我尝试不使用路由,则按 ID 选择可以工作,并且如果没有 id,则有 “缺少参数...”

mysite.com/ws/v1/article - Return all my data (ok) but also a "Missing argument for Articles".

mysite.com/ws/v1/article/6 (6 = id example) Return "The page is not found".

路线

$route['ws/v1/article'] = "api/articles/getArticle";

Controller

public function getArticle_get($id)
{
header("Access-Control-Allow-Origin: *");

// Load Authorization Token Library
$this->load->library('Authorization_Token');

/**
* User Token Validation
*/
$is_valid_token = $this->authorization_token->validateToken();

if (!empty($is_valid_token) AND $is_valid_token['status'] === TRUE)
{
if (empty($id)){
$data = $this->db->get("ga845_clientes")->result();
}else{
$data = $this->db->get_where("ga845_clientes", ['id' => $id])->row_array();
}

$this->response($data, REST_Controller::HTTP_OK);

} else {
$this->response(['status' => FALSE, 'message' => $is_valid_token['message'] ], REST_Controller::HTTP_NOT_FOUND);
}
}

最佳答案

这就是您在 api 中传递参数的方式。

mysite.com/ws/v1/article/$6

要使参数可选,

$route['ws/v1/article/?(:id)?'] = "api/articles/getArticle/$1";

关于php - 带有 $id 的路由或 Codeigniter 中的所有数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58385414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com