Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何用Codeigniter重写URL?_Php_Codeigniter - Fatal编程技术网

Php 如何用Codeigniter重写URL?

Php 如何用Codeigniter重写URL?,php,codeigniter,Php,Codeigniter,在Codeigniter中如何重写URL 我已经尝试过这样改变路线: $route['backend/user/profile/(:num)/'] = 'backend/user/profile/$1/$2'; 但仍然没有什么可以改变 I have url : http://pa.ig/backend/user/profile/204/disabled Url Expected : http://pa.ig/backend/user/profile/204 请帮我把这个修好。 谢谢。如果您的

在Codeigniter中如何重写URL

我已经尝试过这样改变路线:

$route['backend/user/profile/(:num)/'] = 'backend/user/profile/$1/$2';
但仍然没有什么可以改变

I have url : http://pa.ig/backend/user/profile/204/disabled
Url Expected : http://pa.ig/backend/user/profile/204
请帮我把这个修好。
谢谢。

如果您的最后一个参数是字符串,您可以使用
(:any)

$route['backend/user/profile/(:num)/(:any)']  = 'backend/user/profile/$1';

如果第二个参数是可选的,您可以尝试以下操作

在您的路线中

$route['backend/user/profile/(:num)'] = 'backend/user/profile/$1';
$route['backend/user/profile/(:num)/(:string)'] = 'backend/user/profile/$1/$2';
控制器中,为函数的第二个参数提供默认值

public function profile( $id , $stat = 'disabled' ) {
  // your code ..
}

因此,如果在URL中输入第二个参数(
$stat
),它将被禁用

$route['backend/user/profile/(:num)/']到$route['backend/user/profile/(:num)/(:string)]@DIM,因为您有$1/$2,这意味着两个参数。一个是(:num),另一个是缺失的。虽然这段代码可能会回答这个问题,提供关于如何和/或为什么解决问题的附加上下文将提高答案的长期价值。