Php 包含前导斜杠的codeigniter url段
访问该方法的url如下所示: http://localhost/site/cont/method 我想使用GET方法访问此方法,如下所示: http://localhost/new-tera/paper/lookup_doi/segment 但我的部分已经包含/类似于:Php 包含前导斜杠的codeigniter url段,php,codeigniter,uri,Php,Codeigniter,Uri,访问该方法的url如下所示: http://localhost/site/cont/method 我想使用GET方法访问此方法,如下所示: http://localhost/new-tera/paper/lookup_doi/segment 但我的部分已经包含/类似于: public function method ($variable) { echo $variable; } http://localhost/lookup_doi/segment/containing/slashes 请
public function method ($variable)
{
echo $variable;
}
http://localhost/lookup_doi/segment/containing/slashes
请注意,整个段/包含/斜线是一个值
我在我的方法中得到这个值,如下所示:
public function method ($variable)
{
echo $variable;
}
//输出:段
而不是:segment/containing/slashesCodeIgniter将其余部分作为附加参数传递。如果数字是固定的,则可以指定其他参数,也可以使用: implode('/', func_get_args())
获取整个字符串。CodeIgniter将其余字符串作为附加参数传递。如果数字是固定的,则可以指定其他参数,也可以使用: implode('/', func_get_args())
获取整个字符串。您可以通过在查询字符串中添加%2F来添加斜杠,希望这能奏效
segment = 'somethingwith%2F'
http://localhost/new-tera/paper/lookup_doi/segment
您可以通过在查询字符串中添加%2F来添加斜杠,希望这能起作用
segment = 'somethingwith%2F'
http://localhost/new-tera/paper/lookup_doi/segment
您可以先对其进行base64编码,然后再对其进行解码。实际上,您可以使用多种方法将/更改为其他内容,即a-并将其更改回 echo站点_url“controller/method/”。base64_编码$variable 公共函数方法$variable { $variable=base64_解码$variable;
}您可以先对其进行base64编码,然后再对其进行解码。实际上,您可以使用多种方法将/更改为其他内容,即a-并将其更改回 echo站点_url“controller/method/”。base64_编码$variable 公共函数方法$variable { $variable=base64_解码$variable; }.htt检修桅杆应为
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?route=$1 [L,QSA]
所以好吧
$route = empty($_GET['route']) ? '' : $_GET['route'];
$exp = explode('/', $route);
结果:
$exp[0] = new-tera
$exp[1] = paper
$exp[2] = lookup_doi
$exp[3] = segment
这样我们就有了路由!使用我的项目运行示例:
if($exp[0] == '')
{
$file = $_SERVER['DOCUMENT_ROOT'] .'/controllers/controller_index.php';
}
else
{
$file = $_SERVER['DOCUMENT_ROOT'] .'/controllers/controller_'.$exp[0].'.php';
}
if(!file_exists($file))
{
engine :: away();
}
include_once $file;
$class = (empty($exp[0]) or !class_exists($exp[0])) ? 'class_index' : $exp[0];
$controller = new $class;
$method = (empty($exp[1]) or !method_exists($controller, $exp[1])) ? 'index' : $exp[1];
$controller -> $method();
.入口桅杆
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?route=$1 [L,QSA]
所以好吧
$route = empty($_GET['route']) ? '' : $_GET['route'];
$exp = explode('/', $route);
结果:
$exp[0] = new-tera
$exp[1] = paper
$exp[2] = lookup_doi
$exp[3] = segment
这样我们就有了路由!使用我的项目运行示例:
if($exp[0] == '')
{
$file = $_SERVER['DOCUMENT_ROOT'] .'/controllers/controller_index.php';
}
else
{
$file = $_SERVER['DOCUMENT_ROOT'] .'/controllers/controller_'.$exp[0].'.php';
}
if(!file_exists($file))
{
engine :: away();
}
include_once $file;
$class = (empty($exp[0]) or !class_exists($exp[0])) ? 'class_index' : $exp[0];
$controller = new $class;
$method = (empty($exp[1]) or !method_exists($controller, $exp[1])) ? 'index' : $exp[1];
$controller -> $method();