maexus Posted February 26, 2008 Share Posted February 26, 2008 I will start with saying I'm well versed in PHP but never saw a need to implement OOP in any of my projects. I have found it serves a need of mine to keep code clean and neat. Using a page class, I can call the page headers with the construct and call the footers when the script stops running. Keeping along this minimalist mindset and a desire to keep the code as compliant and readable as possible, it made sense to make the doctype, title, css files, ect... properties of the page class. This is basically what my script would look like so far: $page = new page(); $page->doc_type = "HTML 4.01 Strict"; $page->title = "Front Page"; $page->css = array("stylesheet"=>"main.css","alternative"=>"alt.css"); $page->requires_login = 0; $page->min_user_lvl = 1; This obviously doesn't work because you are defining variables after the construct was called. Now, I could declare those variables in the script and pass them as arguments when calling the page class but I would really like to avoid this. Like I said, I have a focus on keeping code compliant and using features as they were designed to be used while keeping clean and minimal code. Does anyone have any advice? Link to comment https://forums.phpfreaks.com/topic/93190-implementing-a-slim-page-class/ Share on other sites More sharing options...
aschk Posted February 27, 2008 Share Posted February 27, 2008 Just have another public function called "render()" and run that last. It should build the page from the components supplied. The problem is you can't expect the page to "know" what you're about to specify after you're created an instance of it. Alternatively try using a pageHelper i.e. <?php class pageHelper { public $doc_type; public $title; public $css; public $requires_login; public $min_user_lvl; } $pageHelper = new pageHelper(); $pageHelper ->doc_type = "HTML 4.01 Strict"; $pageHelper ->title = "Front Page"; $pageHelper ->css = array("stylesheet"=>"main.css","alternative"=>"alt.css"); $pageHelper ->requires_login = 0; $pageHelper ->min_user_lvl = 1; // Hand the helper to the page. $page = new Page($pageHelper); ?> Link to comment https://forums.phpfreaks.com/topic/93190-implementing-a-slim-page-class/#findComment-477873 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.