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

urlFor() shows /blogpost/:postnumber

Chama's Avatar

Chama

06 Aug, 2015 08:41 PM

Hi,

this is my route:

$app->get('/blogpost/:postnumber', function($postnumber) use ($app)

    {

        $app->render('blogpost.htm', array('postnumber' => $postnumber));

    })->conditions(array('postnumber' => '[0-9]{0,}'))->name('blogpost');

Inside blogpost.htm Twig is working...

<a href="{{ urlFor('blogpost') }}{{ postnumber }}">{{ postnumber }}</a>

This should link to /blogpost/12345 (12345 = postnumber) but it creates /blogpost/:postnumber12345

Isn't it possible to create a "clean" link without the :postnumber?

Thanks!
Chama

  1. Support Staff 1 Posted by Andrew Smith on 06 Aug, 2015 11:13 PM

    Andrew Smith's Avatar

    Your code is incorrect, you need to pass a second parameter to the urlFor function.

    <a href="{{ urlFor('blogpost', {postnumber: postnumber}) }}">{{ postnumber }}</a>
    

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