Multi-page Pages (FINALLY!)

Monday, August 2nd, 2010|Beginner tips, Brainstorming|by Romans

Up till now we had to either pile up functions in API class formatted as page_user, page_user_add, page_user_del, or we had to create all those classes, each in it’s own file.

Well – not anymore. Now any page class can have sub-pages. Here how it works:

Sub-pages for pages

You can now define sub-pages inside a page class. System will attempt to class with exact name first, but if now found, it will try shorter classes. For instance, if you call for page page_data_edit_subpage_test:

  • looks for file page/data/edit/subpage/test.php
  • looks for file page/data/edit/subpage.php and function page_test()
  • looks for file page/data/edit.php and function page_subpage_test()
  • looks for file page/data.php and function page_edit_subpage_test()
  • fails with exception that page/data/edit/subpage/test.php is not found (current behavior)

Here is how can you use the function:

function page_data_edit(){
// etc



While looking for pages, classes are not being initialized, however once the appropriate class was found, it will be $api->add()’ed. That means that init() will be fired too. So if you want any common code you want for all sub-pages to be executed, then you should place it there.

In regards from the main page – if there is some code you want to have in your “top-most” page, you should put it inside page::initMainPage();


initMainPage() is being similar to api::initLayout() while page_test have a similar form to Api::page_test format functions.

The Benefit

Main benefit is that this will allow us to create multi-functional pages such as “entity manager”. Here is a short sample:

class Page_EntityManager extends Page {
function initMainPage(){

function page_edit(){
function page_delete(){

Further from here, you should only inherit your page from Page_EntityManager and set controller.

class page_users extends Page_EntityManager {
function init(){

Final Thoughts

I am wondering about one thing. When we inherit class like that, what if we want to disable certain page. One thing is that we could throw some exception. throw new PathFinder_Exception(‘blah’) – would work out properly and bypass the page, but it would be initialized already. Well – I’m not sure about this yet.


Posted August 2, 20106:51 pm

Oh – I must note that this change is only for ApiFrontend. If his works out fine, i’ll also port it into ApiAdmin.

Posted August 18, 20108:30 am

I indeed was tired of creating so much files for each edit :) .. This is a good solution.

[...] Multi-page Pages (FINALLY!) [...]