I’ve implemented a routing for a special page. It’s important for the rendering to get the two variables.
c::set('routes', array(
array(
'pattern' => 'blog/events/archiv/(:any)/(:any)',
'action' => function($yearInfo, $monthInfo) {
$data = array('year' => $yearInfo, 'month'=>$monthInfo);
return array('blog/events/archiv', $data);
}
)
));
Now I tried to combine it with multi language support like this:
c::set('routes', array(
array(
'pattern' => 'my/pattern',
'action' => function () {
return site()->visit('some/page', 'en');
}
)
));
How is it possible to combine both. Means multi language support and variables to the controller? Maybe the full syntax of $site->visit() helps?
Untested, but this should work:
c::set('routes', array(
array(
'pattern' => 'blog/events/archiv/(:any)/(:any)',
'action' => function($yearInfo, $monthInfo) {
site()->visit('blog/events/archiv', 'en');
$data = array('year' => $yearInfo, 'month'=>$monthInfo);
return array('blog/events/archiv', $data);
}
)
));
site()->visit()
returns the Page
object, but you don’t have to return it from your route if you need another response.
2 Likes
This works.
Thanks for fast reply, @lukasbestle !
Maybe add this to the docs?
Yes, I think so too. I will do this later today.
Edit: Now part of the routing docs.
1 Like
If you set the site->visit()
called as the first argument of the array also works in order to get a shorter code
...
$data = array('year' => $yearInfo, 'month'=>$monthInfo);
return array(site()->visit('blog/events/archiv', 'en'), $data);