I’m trying to implement a similar feature, but not throughout the whole site, only on a specific folder.
The folder structure is:
Magazine
-
- issue-1
-
- issue-2
-
- …etc
-
- issue-18
-
-
- article
-
And I want all article urls to be ‘domain.com/article’ instead of ‘domain.com/magazine/issue-n/article’.
Have been reading about routes and lots of helpful posts on here, but am missing something, as I have got everything directing to ‘domain.com/article’ but it’s showing the error page.
Here’s my latest attempt, any pointers would be much appreciated!
c::set('routes', array(
array(
'pattern' => 'magazine/(:any)',
'action' => function($uid) {
$page = page($uid);
if(!$page) $page = page('magazine/issue-' . str::substr($uid, 5) . '/' . $uid);
if(!$page) $page = site()->errorPage();
return site()->visit($page);
}
),
array(
'pattern' => 'magazine/(:any)/(:any)',
'action' => function($issue, $article) {
return go($article);
}
)
));
Edit: The page ‘domain.com/magazine’ must still work, and would it be possible to have ‘domain.com/magazine/issue-n’ also still work?