访问方法的URL是这样的: http://localhost/site/cont/method
我想用GET方法类似这样的访问此方法: http://localhost/new-tera/paper/lookup_doi/segment
,但我segment
部分已经含有/
像这样:
http://localhost/lookup_doi/segment/containing/slashes
注意,整个segment/containing/slashes
是一个值。
我得到我的方法是这样这个值:
public function method ($variable)
{
echo $variable;
}
//输出:段
而不是:段/含有/斜杠
笨通过他们的休息作为附加参数。 您可以指定其他参数(如果数量是固定的),或者使用:
implode('/', func_get_args())
让整个字符串。
的.htaccess桅杆
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();
你可以在你的查询字符串添加“%2F”添加斜线希望这将工作
segment = 'somethingwith%2F'
http://localhost/new-tera/paper/lookup_doi/segment
您可以先的base64编码它和之后进行解码。 真的,你可以使用多种方法来改变/别的东西(即 - ),并改回。
回波SITE_URL( '控制器/方法/' BASE64_ENCODE($变量)。);
公共函数法($变量){$变量= BASE64_DECODE($变量); }