调用未定义的方法 Slim\Http\Request::withStatus()
Call to undefined method Slim\Http\Request::withStatus()
我无法解决这个问题
$_SESSION ['usernam'] 是错误的故意去else
Middleware.php
<?php
$auth = function ($response, $request, $next) {
if (isset($_SESSION['usernam']) and is_array($_SESSION['username'])) {
$response = $next($response, $request);
//$response = $response->withStatus(401)->write('403.phtml');
} else {
$response = $response->withStatus(401)->withHeader('Location', '403.phtml');
}
return $response;
};
错误:
详情
类型:错误
消息:调用未定义的方法 Slim\Http\Request::withStatus()
文件:C:\Users\Geovane\Documents\Dropbox\www\tennis\src\middleware.php
线路:9
痕迹
routes.php
$app->map(['GET', 'POST'], '/login', function ($request, $response, $args) {
//var_dump($_SERVER); exit;
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$data = json_decode(filter_input(INPUT_POST, 'data'));
} else {
$data = 'data';
}
$table = $this->db->table('_users');
$login = $table->where([
'username' => $data->username,
'password' => $data->password
])->get();
if($login->count()){
$_SESSION['username'] = (array)$login->first();
return json_encode('ok');
} else {
return false;
}
});
app.js
$(function() {
$('#log-in').click(function(){
var data = {'username': $('#username').val(), 'password': $('#password').val()};
data = JSON.stringify(data);
$.ajax({
type : 'POST',
url : 'login',
dataType : 'json',
data : {data:data},
success: function(data){
if (data == 'ok'){
window.location.replace("athletes");
} else {
new PNotify({
title: 'Ooops!',
text: 'Username ou Password incorretos.',
type: 'danger',
styling: 'bootstrap3'
});
};
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
new PNotify({
title: 'Oh No!',
text: 'Erro! Por favor, contate o administrador.',
type: 'warning',
styling: 'bootstrap3'
});
}
});
});
});
参数顺序错误,请求响应在下
改变
function ($response, $request, $next) {
对此:
function ($request, $response, $next) {
我无法解决这个问题 $_SESSION ['usernam'] 是错误的故意去else
Middleware.php
<?php
$auth = function ($response, $request, $next) {
if (isset($_SESSION['usernam']) and is_array($_SESSION['username'])) {
$response = $next($response, $request);
//$response = $response->withStatus(401)->write('403.phtml');
} else {
$response = $response->withStatus(401)->withHeader('Location', '403.phtml');
}
return $response;
};
错误:
详情
类型:错误 消息:调用未定义的方法 Slim\Http\Request::withStatus() 文件:C:\Users\Geovane\Documents\Dropbox\www\tennis\src\middleware.php 线路:9 痕迹
routes.php
$app->map(['GET', 'POST'], '/login', function ($request, $response, $args) {
//var_dump($_SERVER); exit;
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$data = json_decode(filter_input(INPUT_POST, 'data'));
} else {
$data = 'data';
}
$table = $this->db->table('_users');
$login = $table->where([
'username' => $data->username,
'password' => $data->password
])->get();
if($login->count()){
$_SESSION['username'] = (array)$login->first();
return json_encode('ok');
} else {
return false;
}
});
app.js
$(function() {
$('#log-in').click(function(){
var data = {'username': $('#username').val(), 'password': $('#password').val()};
data = JSON.stringify(data);
$.ajax({
type : 'POST',
url : 'login',
dataType : 'json',
data : {data:data},
success: function(data){
if (data == 'ok'){
window.location.replace("athletes");
} else {
new PNotify({
title: 'Ooops!',
text: 'Username ou Password incorretos.',
type: 'danger',
styling: 'bootstrap3'
});
};
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
new PNotify({
title: 'Oh No!',
text: 'Erro! Por favor, contate o administrador.',
type: 'warning',
styling: 'bootstrap3'
});
}
});
});
});
参数顺序错误,请求响应在下
改变
function ($response, $request, $next) {
对此:
function ($request, $response, $next) {