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]);
}
function articleAction(){
print_r($this->query_string);
}
function jsAction(){
print_r($_SERVER);
}
}

View File

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

View File

@ -6,7 +6,6 @@
<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">
<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>
</head>
<style>

View File

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

View File

@ -45,7 +45,9 @@ 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){
@ -80,9 +82,9 @@ class Router
//print_r($route);
//echo "</pre>";
if (preg_match($route, $url, $matches)) {
//cho "<pre>";
//print_r($matches);
//echo "</pre>";
echo "<pre>";
print_r($matches);
echo "</pre>";
// Get named capture group values
foreach ($matches as $key => $match) {
if (is_string($key)) {

View File

@ -35,6 +35,15 @@ 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){