Cześć misiaczki,
zacząłem używać AltoRouter i natknąłem się na bolesną przeszkodę.
Otóż w wyświetlanych plikach nie mogę wyświetlać wcześniej zdefiniowanych zmiennych.
Mam np. taki kod:
$test = 'oto moja zmienna';
require 'AltoRouter.php';
/**
* This can be useful if you're using PHP's built-in web server, to serve files like images or css
* @link https://secure.php.net/manual/en/features.commandline.webserver.php
*/
$router = new AltoRouter();
// map homepage
$router->map( 'GET', '/', function() {
include __DIR__ . '/views/home.php';
});
$router->map( 'GET', '/test', function() {
require __DIR__ . '/views/test.php';
});
// map user details page
$router->map( 'GET', '/user/[i:id]/', function( $id ) {
require __DIR__ . '/views/user-details.php';
});
// match current request url
$match = $router->match();
// call closure or throw 404 status
if( is_array($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');
}
I podczas wyświetlania plików test.php i home.php wyskakuje komunikat:
Notice: Undefined variable: test in ... on line 3
Czy można coś z tym zrobić czy w każdym pliku będę musiał includować jakiś plik ze zmiennymi, funkcjami itp?