Development Information

July 5, 2010

Tiny Re-arrangement – Mini MVC

Filed under: Mini MVC Information,Updates — judda @ 10:20 pm

While implementing a new plugin, I realized that the original folder situation for the app/config/ folder would get awful messy fairly quickly. I have done a quick update just to rearrange the folder hierarchy to clean it up a little more.

Sorry for the inconvenience.

July 1, 2010

Mini MVC – How to use – The Configuration File

Filed under: Mini MVC Information,Tutorials — judda @ 11:07 pm

Here I am going to give a quick run down about the the Mini MVC project that I have been working on recently and how to use it.

First, let’s start off with the configuration. As I said in my previous post, it will work right out of the box with no modifications needed. However, sometimes things aren’t always how you want them. In these cases it’s good to know what can easily be changed and what cannot.

In the file: ./app/config/config.php

This is the configuration file which comes with the system by default.

Within this section of the configuration file, there is only one thing that you may need to modify. That is the __SHOWINDEX__ defined value. __SHOWINDEX__ will define whether or not the ‘index.php’ will show up in links which are created using the __INDEXPATH__ defined value. If set to TRUE, then it will be added to the link, otherwise it will not be. This is especially useful if mod_rewrite is not enabled on your server. This will just force the application to send everything through the main page instead of masking the use of the ‘index.php’ page.

/* Break up the current path to contain all information */
$split = preg_split ( '/\//', $_SERVER [ 'SCRIPT_NAME' ], -1, PREG_SPLIT_NO_EMPTY );
/* Allow the user of the script to decide if the index should be included in urls */
define ( '__SHOWINDEX__', false );
/* Define the base path for the script */
define ( '__BASEPATH__', '/' . $split [ 0 ] . '/' );
/* Define the index path for the script depending on previous settings */
define ( '__INDEXPATH__', __BASEPATH__ . ( __SHOWINDEX__ ? 'index.php' : NULL ) );

This following section should not be modified just for ease of use:

/* Define where the system libraries are stored */
define ( '__SYSTEM__', __FULLPATH__ . 'system/' );
define ( '__SYSTEMLIBS__', __SYSTEM__ . 'libraries/' );
define ( '__SYSTEMHELPERS__', __SYSTEM__ . 'helpers/' );
/* Define the application path */
define ( '__APPPATH__', __FULLPATH__ . 'app/' );
/* Define where the user libraries are stored */
define ( '__USERLIBS__', __APPPATH__ . 'libraries/' );
define ( '__USERHELPERS__', __APPPATH__ . 'helpers/' );
/* Define the configuration */
define ( '__CONFIG__', __APPPATH__ . 'config/' );

This spot basically defines everything about where stuff within the application is actually stored. For example, we can see the creation of the links to the system helpers and system libraries paths. If any of these values are changed, the corresponding changes should be made in the ./system/ folders.

Next we move onto the definition of the location of the model, view and controllers directories as well as the configuration directory in case there are any other things which require it.

/* Define the configuration */
define ( '__CONFIG__', __APPPATH__ . 'config/' );
/* Define the model / view / controller directories */
define ( '__MODELS__', __APPPATH__ . 'models/' );
define ( '__VIEWS__', __APPPATH__ . 'views/' );
define ( '__CONTROLLERS__', __APPPATH__ . 'controllers/' );

The next key part is the following:

/* Define whether to enable error message logging or not, and where to store the log */
define ( '__LOGERRORS__', true );
define ( '__ERRORLOG__', 'error_log' );
define ( '__DISPLAYERRORS__', true );

This defines the actions which happen when an error occurs. These errors are not the errors which are send by PHP, but ones generated by the Mini MVC script when trying to complete any of your tasks.

The first two definitions: __LOGERRORS__ and __ERRORLOG__ work hand in hand. If __LOGERRORS__ is set to true, then all of the errors which occur will automatically be appended to the file defined in __ERRORLOG__.

The __DISPLAYERRORS__ definition is currently set to true however, this should only be used in development because it displays all of the error messages on the screen after all of the other scripts have been run (after your controller has been called). This will make it so you reveal a bit to much information to the user as well as invalidates any HTML which has been emitted (it emits more HTML after the </html> tag which is not allowed.

The next section:

/* Define the default class and method */
define ( '__DEFAULTCLASS__', 'main' );
define ( '__DEFAULTFUNCTION__', 'index' );

Just defines what the application should be doing if it hasn’t been provided any information about what controller nor the function to use.

In summary:

Constant Result
__SHOWINDEX__ If true, the urls generated through using __INDEXPATH__ will contain ‘index.php’ in them. For example, becomes
__ERRORLANGUAGE__ Allows you to change the language which the error messages are logged in (currently only English exists)
__LOGERRORS__ If true, whenever Mini MVC detects generates an error, it will append it to the specified data file (__ERRORLOG__)
__DISPLAYERRORS__ If true, all of the error messages generated from Mini MVC will be emitted at the bottom of the page.

Hope this helps to make the configuration file a little more clear. Next step, making controllers.

Mini MVC

Filed under: Mini MVC Information — judda @ 10:29 pm

As previously mentioned, I have finished making a Model View Controller design pattern enforcer for PHP.

Firstly, I must start you off with a video.

Yes, the guy can’t sing … but he does a great overview of MVC.

So what is MVC and how will it help you? Based on the way it is structured, it pushes you in the right direction to creating highly maintainable code. Your code is separated into three main components: models, views and controllers.

  • Models – The part of the application where all of the actual data processing should occur
  • Views – The part of the website which is eventually emitted to the viewer
  • Controllers – Acts as a liasion between the models and the views. This layer will pass any information required to the models back to it in a manner which is required by the model as well as tell the application what should be emitted for the front end (the views to display)

Model View Controller

Image From:

Why use this version of MVC over some of the more renown ones?
Easy … because it is extremely light and doesn’t require tons of additional files to run correctly and it works right out of the box. It is also fully documented and all of the documentation has been compiled and placed online at your finger tips just waiting for you to look through it.

How about fancy plugins and stuff?
There is already one out (a layout manager) and more are in progress.

So what do you get when you download the zipped Mini MVC file?

  • The implementation of MVC
  • Built-in use of my database class (see previous posts about it for more information)
  • Sample controllers and views

Why not take the plunge and try it today?

I’ll be posting examples of how to use it shortly.

For more information about MVC, check out the Wikipedia article on it.

Please feel free to contact me if you have any question / comments / concerns / bugs that you find.

« Newer Posts

Powered by WordPress