Post your controller! |
[eluser]Nick Husher[/eluser]
This is the main "directory" controller for a classifieds project I'm working on in my spare time. Public_Page extends Template_Controller which in turn extends Controller. Template_Controller defines standard methods for constructing pages, so calls to $this->display are automatically inserted into a generic page-level template (changable with a call to $this->set_template). The template for the body of the page is automatically derived from the controller method that was called (captured by PHP's debug_backtrace function, which is probably a misuse of the function, but whatever), so a call to Main->_listing uses the /views/pages/main/_listing.php as its body view. The template controller also defines an error function (for reasons that are obvious in a second) that allows me to display site-wide errors within the current site design. There are other ways to do it, but this seemed the most appropriate. I'm still working on an automated exception catcher to throw up styled 500 errors when something internal goes wrong. The routes.php file remaps any non-special path (the path to the admin and user sections, as well as the special shorturl path) to /get/, so a call to http://example.com/housing/for-rent becomes /index.php/main/get/housing/for-rent. It loops through the segments to figure out what category or listing you're looking at and calls $this->_category or $this->_listing as appropriate. The algorithm is really inefficient; it should really be starting at the last segment and working forward, but for internal reasons that's quite a bit more complex and I haven't bothered to refactor it. I can post the Template_Controller class, but it's a bit of a dog's breakfast. I need to break out repeated functionality into separate functions and improve its configurability before I'd call it "good" code. Code: class Main extends Public_Page { EDIT: Also, I'm using Doctrine PHP as an ORM using my Drop-in PHP Doctrine plugin, that's what all the getChildren() and getNode() business is about. |
Messages In This Thread |
Post your controller! - by El Forum - 08-30-2009, 12:19 AM
Post your controller! - by El Forum - 08-30-2009, 01:36 AM
Post your controller! - by El Forum - 08-30-2009, 07:19 AM
Post your controller! - by El Forum - 08-30-2009, 12:31 PM
Post your controller! - by El Forum - 08-30-2009, 12:44 PM
Post your controller! - by El Forum - 08-30-2009, 08:59 PM
Post your controller! - by El Forum - 08-30-2009, 10:07 PM
Post your controller! - by El Forum - 08-31-2009, 02:13 AM
Post your controller! - by El Forum - 08-31-2009, 03:13 AM
Post your controller! - by El Forum - 08-31-2009, 03:19 AM
Post your controller! - by El Forum - 08-31-2009, 04:43 AM
Post your controller! - by El Forum - 08-31-2009, 04:49 AM
Post your controller! - by El Forum - 09-01-2009, 01:05 AM
Post your controller! - by El Forum - 09-01-2009, 09:30 PM
Post your controller! - by El Forum - 09-02-2009, 02:42 AM
Post your controller! - by El Forum - 09-02-2009, 05:34 AM
Post your controller! - by El Forum - 09-02-2009, 09:02 AM
Post your controller! - by El Forum - 09-02-2009, 09:43 AM
Post your controller! - by El Forum - 09-02-2009, 10:13 AM
Post your controller! - by El Forum - 09-02-2009, 01:13 PM
Post your controller! - by El Forum - 09-03-2009, 06:40 AM
Post your controller! - by El Forum - 11-03-2009, 10:20 PM
Post your controller! - by El Forum - 11-03-2009, 11:02 PM
Post your controller! - by El Forum - 11-03-2009, 11:33 PM
Post your controller! - by El Forum - 11-04-2009, 12:09 AM
Post your controller! - by El Forum - 11-04-2009, 03:36 AM
Post your controller! - by El Forum - 11-04-2009, 07:14 AM
|