2015-01-26 14 views
3

어떤 이유인지 AltoRouter를 시작할 수 없습니다. 가장 기본적인 전화를 시도하고 있지만 아무 일도 일어나지 않습니다. 어떻게 작동시킬 수 있습니까? 내 의 index.php 파일은 다음과 같습니다PHP AltoRouter - GET 요청을받을 수 없습니다.

<?php 

    include('settings/autoload.php'); 

    use app\AltoRouter; 

    $router = new AltoRouter; 

    $router->map('GET', '/', function(){ 

     echo 'It is working'; 
    }); 

$match = $router->match(); 

autoload.php :

<?php 

require_once('app/Router.php'); 
+0

오류 메시지가 있습니까? 빈 페이지? index.php에서 무슨 일이 일어나고 있습니까? – Chococroc

+0

오류가없고 페이지가 비어 있습니다. – Sasha

+0

오류 표시 : http://stackoverflow.com/questions/5911964/cannot-get-php-display-errors-enabled – Chococroc

답변

10

귀하의 문제가 있음을 AltoRouter의 Slim Frameworkdocumentation에 따라 (와는 대조적으로, 어떤 같은 구문을 가지고 보인다), 당신을 위해 요청을 처리하지 않습니다, 오직 과 일치합니다. $router->match()으로 전화하면 원하는 방식으로 요청을 처리하는 데 필요한 모든 정보를 얻을 수 있습니다. 그냥 폐쇄-함수를 호출 할 경우 , 단순히 코드를 수정 :

<?php 

// include AltoRouter in one of the many ways (Autoloader, composer, directly, whatever) 
$router = new AltoRouter(); 

$router->map('GET', '/', function(){ 

    echo 'It is working'; 
}); 

$match = $router->match(); 

// Here comes the new part, taken straight from the docs: 

// call closure or throw 404 status 
if($match && is_callable($match['target'])) { 
     call_user_func_array($match['target'], $match['params']); 
} else { 
     // no route was matched 
     header($_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found'); 
} 

봐라을 - 지금 당신이 원하는 출력을 얻을 수 있습니다!