Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In readme #6

Closed
harikt opened this issue Jan 7, 2012 · 7 comments
Closed

In readme #6

harikt opened this issue Jan 7, 2012 · 7 comments
Assignees
Milestone

Comments

@harikt
Copy link
Member

harikt commented Jan 7, 2012

In the advanced section

method -- The $server['REQUEST_METHOD'] must match one of these values.
secure -- When true the $server['HTTPS'] ,

I feel its $_SERVER , but as I am confused whether you was trying to represent the variable in signature function over

is_match -- A custom callback or closure with the signature function(array $server, \ArrayObject $matches)

Sample code I tried is not working , confusion over the format in documentation . See first example no dot for format , second one has dot for the format . I feel we don't need the dot to be passed . Do you feel so ? Then why ? Normally we say html , atom like so , not .html , .xml etc .

<?php
$package_dir = dirname( __DIR__ ) . '/auraphp/system/package';
$loader = require_once $package_dir . '/Aura.Autoload/scripts/instance.php';
$loader->add('Aura\Router', $package_dir . '/Aura.Router/src/' );
$loader->register();
use Aura\Router\Map;
use Aura\Router\RouteFactory;
$map = new Map(new RouteFactory);
/*
$map->add('home', '/');
$map->add(null, '/{:controller}/{:action}/{:id}');
$map->add('read', '/blog/read/{:id}{:format}', [
    'params' => [
        'id' => '(\d+)',
        'format' => '(\..+)?',
    ],
    'values' => [
        'controller' => 'blog',
        'action' => 'read',
        'format' => '.html',
    ]
]);
*/
$map->add('read', '/blog/read/{:id}{:format}', [
    'params' => [
        'id' => '(\d+)',
        'format' => '(\..+)?',
    ],
    'values' => [
        'controller' => 'blog',
        'action' => 'read',
        'id' => 1,
        'format' => '.html',
    ],
    'secure' => false,
    'method' => ['GET'],
    'routable' => true,
    'is_match' => function(array $server, \ArrayObject $matches) {

        // disallow matching if referred from example.com
        if ($server['HTTP_REFERER'] == 'http://example.com') {
            return false;
        }

        // add the referer from $server to the match values
        $matches['referer'] = $server['HTTP_REFERER'];
        return true;

    },
    'generate' => function(\Aura\Router\Route $route, array $data) {
        $data['foo'] = 'bar';
        return $data;
    }
]);

$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);

$route = $map->match($path, $_SERVER);
if (! $route) {
    // no route object was returned
    echo "No application route was found for that URI path.";
    exit;
}
echo " Controller : " . $route->values['controller'];
echo " Action : " . $route->values['action'];
echo " Format : " . $route->values['format'];

I have started the server with

$ php -s localhost:8000 

from the default directory . I guess, the error is throwing by Apache and not by Router itself .

@ghost ghost assigned pmjones Jan 7, 2012
@harikt
Copy link
Member Author

harikt commented Jan 7, 2012

In the format

        'params' => [
            'id'     => '(\d+)',
            'format' => '(\.json|\.atom)?'
        ],
        'values' => [
            'format' => '.html',
        ],

I don't think we need the dot , can we remove that if so ?

@harikt
Copy link
Member Author

harikt commented Jan 11, 2012

Do we need to create any .htaccess file ? The path http://localhost:8000/blog/read/1 is ok , but when a .html or .json is added it just throws Not Found .

@harikt
Copy link
Member Author

harikt commented Jan 20, 2012

@pmjones may be you want to investigate into this before we go for next release . I feel its due to my php installation issue , but not sure though.
Thank you

@pmjones
Copy link
Member

pmjones commented Jan 23, 2012

Regarding $server vs $_SERVER, the use of $server is to indicate the object property, as vs the PHP superglobal. The $server property gets populated from the globals, but its value may change independently of $_SERVER.

@pmjones
Copy link
Member

pmjones commented Jan 23, 2012

There's a bug in Route::isSecureMatch(); it uses = when it should use ==. Fixing and testing now, and adding debugging/logging methods so other problems will be easier to diagnose.

@pmjones
Copy link
Member

pmjones commented Jan 23, 2012

Fixed, committed, and pushed. Try it again; if you still have trouble, please open a new issue. Thanks HariKT !

@pmjones pmjones closed this as completed Jan 23, 2012
@harikt
Copy link
Member Author

harikt commented Jan 23, 2012

@pmjones opened issue #7 . Not sure whether its with some php configuration issue .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants