The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

wrong routing

drivefast's Avatar

drivefast

14 Mar, 2012 10:42 PM

here is a slight modification of the "hello world" application.

<?php
require_once("/some/directory/Slim/Slim.php");
$app = new Slim();

$app->get("hello/:name", function($name) {
    echo "Hello, $name";
});

$app->get("/", function() use ($app) {
    echo "Hello, nobody<br>";
    echo "param=" . $app->request()->get('param') . "<br>";
    echo "root: '" . $app->request()->getRootUri() . "'<br>";
    echo "resource: '" . $app->request()->getResourceUri() . "'<br>";
});

$app->run();
?>

now for an url like

http://rest.mywebsite.com/hello/there?param=value

i get the response:

Hello, nobody
param=value
root: '/hello/there'
resource: '/'

so it's pretty clear that my root path is incorrectly determined, and thus the resource is misinterpreted. instead of having the first app->get() function called, the second one gets called, and the printout of the request internal variables indicate the source of the problem.

as something that i consider related, i must say that initially i had quite some trouble with the contents of the .htaccess file. i moved the mod_rewrite configuration in the httpd.conf, like this:

<VirtualHost x.x.x.x:80>
    DocumentRoot /path/to/rest/
    ServerName rest.mywebsite.com
    RewriteEngine On
    RewriteLog "/tmp/rw.log"
    RewriteLogLevel 9
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php [QSA,L]
</VirtualHost>

note that i am running the slim framework in a subdomain. also, i had to change the rewrite rule to /index.php, as opposed to just index.php - if this matters in any way. OS is centos 6, http server is apache, php is 5.3.3.

anybody has a clue on what could i have screwed up with my settings? really appreciated.

  1. Support Staff 1 Posted by Josh Lockhart on 25 Mar, 2012 03:22 PM

    Josh Lockhart's Avatar

    In your example, the first route's pattern must have a leading forward slash; currently, it does not. It should look like:

    $app->get('/hello/:name', function ($name) {
        echo "Hello, $name";
    });
    

    Let me know if this resolves the issue.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac