controller 添加了获取query的支持

deploy
caiyuzheng 2019-08-28 17:16:03 +08:00
parent d45de82ad0
commit 3f7b1be400
6 changed files with 19 additions and 14 deletions

View File

@ -26,10 +26,9 @@ class Blog extends Controller
View::renderTemplate("/blog/basic.html",['docs'=>$docs,'index'=>false]); View::renderTemplate("/blog/basic.html",['docs'=>$docs,'index'=>false]);
} }
function articleAction(){ function articleAction(){
print_r($this->query_string);
} }
function jsAction(){ function jsAction(){
print_r($_SERVER); print_r($_SERVER);
} }
} }

View File

@ -18,10 +18,7 @@ class Home extends \Core\Controller
* @return void * @return void
*/ */
public function indexAction() { public function indexAction() {
$ret = [];
$ret[1] = "hello";
//View::renderTemplate('Home/index.html');
$this->JsonResp(200,$ret,"OK");
} }
public function usersAction() { public function usersAction() {
$user = Models\User::getAll(); $user = Models\User::getAll();

View File

@ -6,7 +6,6 @@
<script type="text/javascript" src="/api/App/Views/blog/js/jquery.js"></script> <script type="text/javascript" src="/api/App/Views/blog/js/jquery.js"></script>
<link href="/api/App/Views/blog/css/left.css" rel="stylesheet" type="text/css"> <link href="/api/App/Views/blog/css/left.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/api/App/Views/blog/js/left.js"></script> <script type="text/javascript" src="/api/App/Views/blog/js/left.js"></script>
<script type="text/javascript" src="/api/App/Views/blog/js/showdown.min.js"></script>
<script type="text/javascript" src="/api/App/Views/blog/js/scripts.js"></script> <script type="text/javascript" src="/api/App/Views/blog/js/scripts.js"></script>
</head> </head>
<style> <style>

View File

@ -20,6 +20,7 @@ abstract class Controller
public $body ; public $body ;
protected $input; protected $input;
protected $debug = false; protected $debug = false;
protected $query_string;
/** /**
* Class constructor * Class constructor
* *
@ -29,13 +30,13 @@ abstract class Controller
*/ */
public function __construct($route_params) public function __construct($route_params)
{ {
switch($_SERVER['CONTENT_TYPE']){ switch($_SERVER['CONTENT_TYPE']){
case 'application/json': case 'application/json':
$this->body = file_get_contents('php://input'); $this->body = file_get_contents('php://input');
$this->input = json_decode($this->body); $this->input = json_decode($this->body);
break; break;
} }
$this->query_string = $_SERVER["QUERY_STRING"];
$this->route_params = $route_params; $this->route_params = $route_params;
} }
/** /**
@ -52,11 +53,9 @@ abstract class Controller
public function __call($name, $args) public function __call($name, $args)
{ {
$method = $name . 'Action'; $method = $name . 'Action';
if (method_exists($this, $method)) { if (method_exists($this, $method)) {
if ($this->before() !== false) { if ($this->before() !== false) {
call_user_func_array([$this, $method], $args); call_user_func_array([$this, $method], $args);
$this->after(); $this->after();
} }
} else { } else {

View File

@ -45,7 +45,9 @@ class Router
// Add start and end delimiters, and case insensitive flag // Add start and end delimiters, and case insensitive flag
$route = '/^' . $route . '$/i'; $route = '/^' . $route . '$/i';
echo '<pre>';
print_r($route);
echo '</pre>';
$this->routes[$route] = $params; $this->routes[$route] = $params;
} }
public function AddPrefix($prefix){ public function AddPrefix($prefix){
@ -80,9 +82,9 @@ class Router
//print_r($route); //print_r($route);
//echo "</pre>"; //echo "</pre>";
if (preg_match($route, $url, $matches)) { if (preg_match($route, $url, $matches)) {
//cho "<pre>"; echo "<pre>";
//print_r($matches); print_r($matches);
//echo "</pre>"; echo "</pre>";
// Get named capture group values // Get named capture group values
foreach ($matches as $key => $match) { foreach ($matches as $key => $match) {
if (is_string($key)) { if (is_string($key)) {

View File

@ -35,6 +35,15 @@ try{
print ""; print "";
return; return;
}else{ }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']); $router->dispatch($_SERVER['REQUEST_URI']);
} }
}catch (Exception $exception){ }catch (Exception $exception){