2017-05-11 1 views
0

이 $ _SESSION은 [ 'usernam는']를 다른 사람에 갈 목적에 잘못전화 : withStatus() 나는이 문제를 해결할 수없는

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; 
}; 

오류 :

세부

유형 : 에로 R 메시지 : 정의되지 않은 메서드 호출 슬림 \ HTTP를 \ 요청 :: withStatus() 파일 : C : \ 사용자 \ Geovane 문서 \ 드롭 박스 \ www가 \ 테니스 \ \ 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; 
} 
}); 

는 매개 변수의 순서이 W

$(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' 
       }); 
      } 
     }); 
    }); 
}); 

답변

1

을 app.js rong, 다음에 요청 응답. 이것에

변경

function ($response, $request, $next) { 

:

function ($request, $response, $next) { 
관련 문제