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:

  • common.inc.php
  • header.inc.php
  • footer.inc.php
  • classes/class.inc.php
  • view.php
  • c_controller.php

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.

common.inc.php

This is the core file that allows your entire system to run.  Includes to autoloaders, globals, settings, required functions, etc., all live here.

header.inc.php

This file generally starts with an include to the common.inc.php file, then starts building out the beginning of the HTML.  That includes includes for javascript and css files as well as either housing the nav directly in this file, or if it’s more complex (or variable), includes the nav as necessary.  The view.php page that includes this header.inc.php file can also set various variables which are examine here such as $login_required or $use_ck_editor.

footer.inc.php

Closes up the header’s HTML, might append memory usage or page run-time statistics if needed or desired.

classes/class.inc.php

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.

view.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.

c_controller.php

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.

September 22nd, 2015

Posted In: Uncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: