Hello everyone!
I’m writing this question because I tried to follow the docs and the advices in the other forum thread without success.
I’m setting up a multilanguage site (‘it’ as default, ‘en’ and ‘de’) with the following folder structure:
- home
- error
- Page1
- Page1Subpage1
- Page1Subpage2
- Page2
- Page2Subpage1
- Page2Subpage2
I’m setting for each page a proper URL Key and everything is perfect. My problem is that I would like to make all the pages act as a first level page. Page1 and Page2 are only containers, but and i would like to mantain them because of the number of final pages.
Following the docs i tried to set up these routes:
c::set('routes', array(
array(
'pattern' => '(:any)',
'action' => function($uid) {
$page = page($uid);
if(!$page) $page = page('page1/' . $uid);
if(!$page) $page = page('page2/' . $uid);
if(!$page) $page = site()->errorPage();
return site()->visit($page);
}
),
array(
'pattern' => array(
'page1/(:any)',
'en/page1/(:any)',
'de/page1/(:any)',
'page2/(:any)',
'en/page2/(:any)',
'de/page2/(:any)'),
'action' => function($uid) {
go($uid);
}
)
));
This doesn’t work, because I’m getting the URL Key, not the UID. I tried to get the page with these routes but i doesn’t work:
c::set('routes', array(
array(
'pattern' => '(:any)',
'action' => function($urlkey) {
$page = site()->findBy('urlkey', $urlkey);
if(!$page) $page = site()->errorPage();
return site()->visit($page);
}
),
array(
'pattern' => array(
'page1/(:any)',
'en/page1/(:any)',
'de/page1/(:any)',
'page2/(:any)',
'en/page2/(:any)',
'de/page2/(:any)'),
'action' => function($uid) {
go($uid);
}
)
));
I understand that I’m not getting the right page object and that I should pass the right language code to the ‘site()->visit($page)’ function.
If needed, I could do a compromise and keep the language code in my urls (ex. domain.com/en/Page1Subpage1)… But I cannot find a solution, so I’m here to ask for advices
Thanks to everyone for the help!