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.
|__SHOWINDEX__||If true, the urls generated through using __INDEXPATH__ will contain ‘index.php’ in them. For example, http://www.yoursite.com/model/controller becomes http://www.yoursite.com/index.php/model/controller|
|__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.