改进控制器方法的参数 支持使用Request对象 自动传入当前请求对象

This commit is contained in:
thinkphp
2016-05-27 11:06:19 +08:00
parent b228efdc00
commit 46ce08b962
3 changed files with 5 additions and 3 deletions

View File

@@ -194,7 +194,9 @@ class App
$params = $reflect->getParameters();
foreach ($params as $param) {
$name = $param->getName();
if (1 == $type && !empty($vars)) {
if ('think\Request' == $param->getClass()->name) {
$args[] = Request::instance();
} elseif (1 == $type && !empty($vars)) {
$args[] = array_shift($vars);
} elseif (0 == $type && isset($vars[$name])) {
$args[] = $vars[$name];

View File

@@ -342,7 +342,7 @@ class Input
// TODO 其他安全过滤
// 过滤查询特殊字符
if (preg_match('/^(EXP|NEQ|GT|EGT|LT|ELT|OR|XOR|LIKE|NOTLIKE|NOT BETWEEN|NOTBETWEEN|BETWEEN|NOTIN|NOT IN|IN)$/i', $value)) {
if (is_string($value) && preg_match('/^(EXP|NEQ|GT|EGT|LT|ELT|OR|XOR|LIKE|NOTLIKE|NOT BETWEEN|NOTBETWEEN|BETWEEN|NOTIN|NOT IN|IN)$/i', $value)) {
$value .= ' ';
}
}

View File

@@ -28,8 +28,8 @@ class Route
private static $rest = [
'index' => ['GET', '', 'index'],
'create' => ['GET', '/create', 'create'],
'read' => ['GET', '/:id', 'read'],
'edit' => ['GET', '/:id/edit', 'edit'],
'read' => ['GET', '/:id', 'read'],
'save' => ['POST', '', 'save'],
'update' => ['PUT', '/:id', 'update'],
'delete' => ['DELETE', '/:id', 'delete'],