Lately I’ve created a variety of projects and I’ve modified my command structure just slightly. This new method has a couple minor advantages, but still utilizes the essentials of the command structure.
The overall file structure of a project looks something like this:
In the new view.php and c_controller.php files, I’m still using my command structure, but the controller is contained (more or less) exclusively within the c_controller.php file. This lets me include only the common file (instead of the header which then includes the common file), and lets me have a nice redirect statement at the bottom of the file to redirect back to wherever the user was before the controller was called, which makes the code even more easily reusable.
This is the core file that allows your entire system to run. Includes to autoloaders, globals, settings, required functions, etc., all live here.
Closes up the header’s HTML, might append memory usage or page run-time statistics if needed or desired.
I generally have one class file per MySQL table plus other classes for significant object-oriented functions. UI, string, array, and date object classes can all live in here as well. Example filenames might be user.inc.php, job.inc.php, company.inc.php.
This will display whatever content you’re trying to show to the user. It can optionally use the command structure as well. Typically this is some kind of a list-of-elements page, or a view-detail or edit-item page. Example file names might be users.php, user.php, jobs.php, job_edit.php, etc.
This is generally executed from buttons or links clicked on view.php pages, will process some kind of work, and redirect the user back to a view.php page. This file always uses the command structure so that multiple control segments can live within a single file. If the user needs to land on a particular page, that can be specified in the command segment, or the specified landing page can be omitted and the script will redirect the user back to the page they were previously on. Example file names might be c_user.php, c_job.php, c_company.php, etc.
Michael Berding September 22nd, 2015
Posted In: Uncategorized