Hello!
I’m kinda new in web programming and at using frameworks. I have a small problem by getting an error when I put a getter on a page with an argument. The odd thing is that actually works, but I still get an error when I’m not on this page.
The error is the following :
Message: An exception has been thrown during the rendering of a template (“Missing data for URL segment: userprofile”) in “layout.twig” at line 19.
And here’s the precise case:
I did the basic routing with an argument like this :
projectname/profile/foo
to get something like this:
Hello foo
So here’s how I did it:
From the index.php I got the get for the profile page:
$app->get('/profile/{userprofile}', 'App\Controllers\PagesController:getProfile')->setName('user.profile');
My getProfile function (I made a render function to avoid writing $this->container->view->[…] ):
public function getProfile($request, $response, $args) {
$userprofile = $args['userprofile'];
return $this->render($response, 'pages/profile.twig',[
'userprofile' => $userprofile
]);
}
Here’s my profile.twig file:
{% block content %}
Hello {{userprofile}}
{% endblock %}
Here’s my layout.twig:
<li><a href="{{ path_for('user.profile') }}"><span class="glyphicon glyphicon-user"></span> Profile</a></li>
So again, it WORKS when I’m in this page, but get the twig error outside of this page. (Excepted on /profile without arguments, where I get a classic Page not found error).
Did I missed something? (Probably yes, but what? ).
Thanks for your time!