添加路由模块解析query参数
parent
c4be46d55a
commit
2f2dba60bc
|
@ -23,11 +23,11 @@ class Blog extends Controller
|
|||
$obj['content'] = $content;
|
||||
array_push($docs,$obj);
|
||||
}
|
||||
View::renderTemplate("/blog/basic.html",['docs'=>$docs,'index'=>false]);
|
||||
View::renderTemplate("/blog/basic.html",['docs'=>$docs,'index'=>true]);
|
||||
}
|
||||
function articleAction(){
|
||||
View::renderTemplate("/blog/basic.html",['docs'=>null,'index'=>false]);
|
||||
print_r($this->query_string);
|
||||
View::renderTemplate("/blog/basic.html",['title'=>'test','index'=>false]);
|
||||
//print_r($this->query_string);
|
||||
}
|
||||
function jsAction(){
|
||||
print_r($_SERVER);
|
||||
|
|
|
@ -132,10 +132,15 @@
|
|||
<p style="vertical-align: bottom;font-size: 12px;">read more</p>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
{% if title != '' %}
|
||||
|
||||
{% endif %}
|
||||
{%else%}
|
||||
<div style="width: 670px; height: 100%; border-bottom: #0b58a2 solid 1px ;margin: 5px 5px 5px 5px;">
|
||||
<p style="display: block;font-size: 16px;text-align: center;">
|
||||
测试
|
||||
</p>
|
||||
<div style="width: 670px;height: 800px; display: block;font-size: 10px;text-align: left;">
|
||||
发送到发的说法
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -36,7 +36,15 @@ abstract class Controller
|
|||
$this->input = json_decode($this->body);
|
||||
break;
|
||||
}
|
||||
$this->query_string = $_SERVER["QUERY_STRING"];
|
||||
preg_match("/^.{0,}\?(.{0,})$/i", $_SERVER['REQUEST_URI'], $matches);
|
||||
if(sizeof($matches) > 0){
|
||||
$pieces = explode("=", $matches['1']);
|
||||
print_r(sizeof($pieces));
|
||||
for ($i = 0;$i < sizeof($pieces) /2 ;$i++){
|
||||
print $i;
|
||||
$this->querys[$pieces[2*$i]] = $pieces[2*$i + 1];
|
||||
}
|
||||
}
|
||||
$this->route_params = $route_params;
|
||||
}
|
||||
/**
|
||||
|
|
|
@ -45,9 +45,7 @@ class Router
|
|||
|
||||
// Add start and end delimiters, and case insensitive flag
|
||||
$route = '/^' . $route . '$/i';
|
||||
echo '<pre>';
|
||||
print_r($route);
|
||||
echo '</pre>';
|
||||
|
||||
$this->routes[$route] = $params;
|
||||
}
|
||||
public function AddPrefix($prefix){
|
||||
|
@ -82,9 +80,6 @@ class Router
|
|||
//print_r($route);
|
||||
//echo "</pre>";
|
||||
if (preg_match($route, $url, $matches)) {
|
||||
echo "<pre>";
|
||||
print_r($matches);
|
||||
echo "</pre>";
|
||||
// Get named capture group values
|
||||
foreach ($matches as $key => $match) {
|
||||
if (is_string($key)) {
|
||||
|
@ -120,7 +115,6 @@ class Router
|
|||
{
|
||||
$url = $this->removeQueryStringVariables($url);
|
||||
$url = str_replace($this->prefix,"",$url);
|
||||
|
||||
if ($this->match($url)) {
|
||||
$controller = $this->params['controller'];
|
||||
$controller = $this->convertToStudlyCaps($controller);
|
||||
|
@ -195,9 +189,9 @@ class Router
|
|||
protected function removeQueryStringVariables($url)
|
||||
{
|
||||
if ($url != '') {
|
||||
$parts = explode('&', $url, 2);
|
||||
$parts = explode('?', $url, 2);
|
||||
|
||||
if (strpos($parts[0], '=') === false) {
|
||||
if (strstr($parts[0], '=') === false) {
|
||||
$url = $parts[0];
|
||||
} else {
|
||||
$url = '';
|
||||
|
@ -219,7 +213,7 @@ class Router
|
|||
$namespace = 'App\Controllers\\';
|
||||
|
||||
if (array_key_exists('namespace', $this->params)) {
|
||||
$namespace .= $this->params['namespace'] . '\\';
|
||||
$namespace .= $this->params['namespace'] . '\\';
|
||||
}
|
||||
|
||||
return $namespace;
|
||||
|
|
|
@ -35,15 +35,7 @@ try{
|
|||
print "";
|
||||
return;
|
||||
}else{
|
||||
print_r($_SERVER["REQUEST_URI"]);
|
||||
preg_match("/^.{0,}\?(.{0,})$/i", $_SERVER['REQUEST_URI'], $matches);
|
||||
echo '<pre>';
|
||||
print_r($matches['1']);
|
||||
echo '</pre>';
|
||||
$pieces = explode("=", $matches['1']);
|
||||
echo '<pre>';
|
||||
print_r($pieces);
|
||||
echo '</pre>';
|
||||
|
||||
$router->dispatch($_SERVER['REQUEST_URI']);
|
||||
}
|
||||
}catch (Exception $exception){
|
||||
|
|
Loading…
Reference in New Issue