In order to learn Fat-Free-Framework, I decided to start tweaking Fabulog to add support for Pages (I can share my code when I am done)
Here is what I did:
1 ) Created a new model "Page", new Admin views "page-list.html", "page_edit.html", "page_layout.html", and a new controller "Page". Obviously, these are tweaked copies of your Post versions.
2 ) I added the Page section in the admin menu
3 ) I changed the routing at follows:
// view list
$f3->route(array(
'GET /',
'GET /page/@page'
),'Controller\Post->getList');
// view single
// pages have priority: if the slug isn't found in page, we will call Post->getsingle
$f3->route(array(
'GET /@slug',
'GET /p/@slug',
), 'Controller\Page->getSingle');
$f3->route(array(
'GET /post/@id'
), 'Controller\Post->getSingle');
4 ) In my page not found handling, I added this:
if ($this->resource->dry()){
if (!isset($params['id'])) {
$postcontroller= new Post();
$postcontroller->getSingle($f3, $params);
/*
$f3->route(array(
'GET /'. $params['slug'],
), 'Controller\Page->getSingle');
*/
}
else{
$f3->error(404, 'Page not found');
}
}
But neither methods work...
I instead get a page without the post loaded.
I can simply redirect to /post/@slug
But I was hoping to avoid doing that...
Do you have any ideas?
Here are my thoughts:
1 ) I do not yet fully understand the resource, so it's quite possible that the resource is still trying to work with pages.
2 ) Perhaps it's not possible to route or call a new controller from within a controller without extra initialization?