无法在 CodeIgniter 中获取 URL 参数
Cant get URL parameters in CodeIgniter
我试图从 URL "myfolder/mycontroller/mymethode/123"
访问一个 ID,我将其调用到 AJAX 调用中。
我无法访问它们,在 "mymethode"
下的 "mycontroller"
中。我试图输出 $_GET, $_POST, $this->input->get(), $this->input->post()
,但所有数组都是空的。
在 Controller/mycontroller
我有这个
public function mymethode($listid=false)
{
echo "listid: $listid";
print_r($_GET);
print_r($_POST);
print_r($this->input->get());
print_r($this->input->post());
}
Ajax 调用是这样的,可以使用状态 200。
$.ajax({
url: http://mydomein.com/myfolder/mycontroller/mymethode/123,
type: "POST",
method: 'post',
data: form + "&" + additional_data + csrfName + "=" + csrfHash,
dataType: 'json',
cache: false,
success: function(res){...
如果我尝试直接打开URL,我遇到了同样的问题。
会是什么原因呢?
使用这个(如果这不是 HMVC)
在route.php
# You may need first route since you're accepting null on method
$route['mymethode] = 'mycontroller/mymethode';
$route['mymethode/(:num)'] = 'mycontroller/mymethode/';
在AJAX
url: http://mydomein.com/mymethode/123,
在控制器中
public function mymethode($listid=null)
我试图从 URL "myfolder/mycontroller/mymethode/123"
访问一个 ID,我将其调用到 AJAX 调用中。
我无法访问它们,在 "mymethode"
下的 "mycontroller"
中。我试图输出 $_GET, $_POST, $this->input->get(), $this->input->post()
,但所有数组都是空的。
在 Controller/mycontroller
我有这个
public function mymethode($listid=false)
{
echo "listid: $listid";
print_r($_GET);
print_r($_POST);
print_r($this->input->get());
print_r($this->input->post());
}
Ajax 调用是这样的,可以使用状态 200。
$.ajax({
url: http://mydomein.com/myfolder/mycontroller/mymethode/123,
type: "POST",
method: 'post',
data: form + "&" + additional_data + csrfName + "=" + csrfHash,
dataType: 'json',
cache: false,
success: function(res){...
如果我尝试直接打开URL,我遇到了同样的问题。
会是什么原因呢?
使用这个(如果这不是 HMVC)
在route.php
# You may need first route since you're accepting null on method
$route['mymethode] = 'mycontroller/mymethode';
$route['mymethode/(:num)'] = 'mycontroller/mymethode/';
在AJAX
url: http://mydomein.com/mymethode/123,
在控制器中
public function mymethode($listid=null)