dolmoboy's avatar

Routing problems with Lumen 404 error.

Hi there! A friend and I recently tried the Lumen framework and we have encountered some problems.

Basically we when we make a GET/POST petition for example through a simple form with action="contact" the resultant URL looks something like this

http://localhost/public/contact?name=John&email=someEmailATemail.com

and it should be something like

http://localhost/public/contact/John/someEmailatemail.com

so when we tried to route it like this

$app->post('contact/{name}/{email}', 'ContactController@sendEmail');

We get an 404 error bacause its doesn't match it, even if we try something like this:

$app->post('contact?name={name}&email={email}', 'ContactController@sendEmail');

We get the same 404 error.

We are using xampp over windows, but we also tried Homestead and vagrant and we got the same problem.

Mod_rewrite is installed and working and I have my .htaccess file under the public folder with the default content:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

If I try to route any get petition like:

$app->get('contact/{name}/{email}', 'ContactController@sendEmail');

and type on the browser adressbar

http://localhost/public/contact/John/someEmailATemail.com

it works perfectly.

Thank you all for the time and help!

0 likes
2 replies
ersinkandemir's avatar
Level 1

Route parameters and form parameters are disparate. Once you submit a form, it builds a query on form's action url with form parameters: action_url?name=Ersin&mail=mailAtDomainCom.

$app->get('contact/{name}/{email}', 'ContactController@sendEmail');

Above usage is a route parameter, not a form parameter. If you really want to post your values as a route parameter, you should do a javascript trick to build form's action url as to match route before the form submits.

1 like
dolmoboy's avatar

Thats exactly what I did, a JS function that builds the url to match the route before sending the form, it actually work pretty ok with both GET and POST methods. Just a minor issue, since my function reads the form's inputs and then builds the URL, when I do a POST submit the URL is the same as if it were GET, I'm guessing there is no way to hide the parameters and still match the route right?

Thank you ersinkandemir!

Please or to participate in this conversation.