PHP Configuration

MogulMVC is built with certain design and organizational patterns in mind. These design and organizational patterns make sense to use and so we make them the default configuration.

However, one size fits all never looks good. Because of that we made our configuration section as robust as possibly while also remaining as organized as possible.

Below are the every configuration file available in the MogulMVC application/config directory.

These configuration file affect all directory naming and organization in the application as well as routing, database connectivity, and session management.

Autoload - autoload.php

MogulMVC can load css, js, and php libraries every time the framework runs. CSS and JS loaded with autoload will also be automatically minified when switching an application from development to production mode.

Autoload can load library files from 8 locations.

    Autoloaded CSS will appear in the head by default.
    Autoloaded JS will appear in the foot by default.

    Precompiled CSS and JS files should be placed in the public/css/ and the public/js/ directories respectively.

    CSS and JS needing to be dynamically compiled with PHP should be placed in the lib/css/ and lib/js/ directories respectively.

  • -- The framework's CSS directory.
  • -- The application's CSS directory.
  • -- External CSS.
  • -- The framework's CSS directory.
  • -- The application's JS directory.
  • -- External JS.
  • -- The framework's PHP directory.
  • -- The application's PHP directory.


To autoload a library open the autoload.php file and add the location of the file inside the appropriate array. Files should be specified from the base directory of the type of library being loaded. Base directory of the files comes from config.php.

A third party PHP library called SomeLibrary.php would by default be placed in /application/lib/php/vendor/SomeLibrary.php and be loaded as follows.

$GLOBALS['AUTOLOAD_PHP_APPLICATION'] = array('vendor/SomeLibrary');

As you can see file extensions are not needed as the framework determines the correct file extension. This is true for locally stored CSS and JS as well.

$GLOBALS['AUTOLOAD_CSS_APPLICATION'] = array('vendor/SomeLibrary');
$GLOBALS['AUTOLOAD_JS_APPLICATION'] = array('vendor/SomeLibrary');


Always name your CSS and JS library files with dashes instead of periods, otherwise MogulMVC will error when loading your file.

jquery.scrollTo.js should be jquery-scrollTo.js

Config - config.php

The config.php file allows you to specify most organizational components of your application as well as select a default head, header, footer, foot, and controller.

All configuration options are defined as constants.

Application Information

All MogulMVC applications need a company, name, description, password, and version.

These constants are used during the creation of pages and loading of assets such as images, CSS, and JS files.

The password is needed when running commands from the CLI and web interface.


There are two environments MogulMVC can be run in, development and production.

When in development mode all errors will be displayed and all CSS and JS will be loaded from seperate files.

When in production mode no errors will be displayed and MogulMVC will automatically combine and minify all CSS and JS files loaded from the autoload.php.

Action and API

Action and API files are special controller files for reciving and broadcasting data. MogulMVC needs a special URL keyword to invoke action and api requests as instead of looking for normal controllers.


Organiztion is key in MogulMVC. Each file you create has a place to be put, but we allow you to rename and change these places. The config.php directories section is where you can change the default directories MogulMVC uses to store and load your files.


A default controller is the controller that runs at the root of your site.

A 404 controller, as the name suggests, runs when an 404 error is thrown.


Templates define the default head, header, footer, and foot files to be used in an application. These file will automatically be included when rendering a view.

Constants - constants.php

MogulMVC allows you to define constants to be used throughout the application at a very low level of the application run process. Constants are created shortly after the core libraries are in included but before the desired controller is instantiated.

To create a constant open the constants file and add a constant as you normally would in PHP.

Database - database.php

Database configuration is setup in the database.php file inside the config directory. Each database is an associative array inside of the $GLOBALS['DB'] array. Each database that is configured needs 6 indexes specified and must be a unique index inside of the $GLOBALS['DB'] array.

The following code shows an example of a connection to a MySQL database.

'connection_name' => array(
	'type' => 'mysql',
	'host' => 'localhost',
	'port' => '3306',
	'name' => 'dbname',
	'user' => 'dbuser',
	'pass' => 'dbpass'
MogulMVC supports any database connection that PDO supports. To get more information about using databases see PHP Models.

Routes - routes.php

By default MogulMVC maps a URL to a controller class and function in the following way.

Sometimes you want to map routes differently, for example, a video site might require a URL as follows.

Obviously a function can't be made for each video id, thus this is a prime use of routes.

MogulMVC has four different route types. Anything to a controller and function, a number to a controller and function, a string to a controller and function, and a page to a controller and function.

The above example would use a number to a controller and function and might use the following route.

$ROUTE['media/#'] = 'Media/index';

The code to grab the video id and pull the data from the database would be in the index function within the Media controller.

The following code is found within the routes.php file found in the config directory. It shows how to map any of the four types of routes.

Any subpage to controller with function.
$ROUTE['page/*'] = 'Controller/function';
Any number to controller with function.
$ROUTE['page/#'] = 'Controller/function';
Any string to controller with function.
$ROUTE['page/@'] = 'Controller/function';
Page to controller with function.
$ROUTE['page/subpage'] = 'Controller/function';

Sessions - session.php

The web is traditionally stateless, meaning it does not remember variables from user to user like a desktop application would. Sessions are a way around this. They allow us to remember user specific information by keeping a token on both the server and the client machine and on future requests using that token to retrieve data stored in memory. However, this causes a problem when more than one server is hooked up on a network. The first user request may be handled by server A, which creates a session in memory. The second request may then be handled by server B, which does not have the session stored in memory.

MogulMVC sessions allow you to store sessions in a centrally accessible database. MogulMVC stores sessions in JSON format so they are cross language compatible.

To use database sessions you must create a database and table to use with sessions.

The command directory contains a prewritten command to automatically create the session table once you manually create a session database. The information needed for this command and sessions in general is configured within the session.php file. Populate the $GLOBALS['SESSION'] object with the appropriate information.

'type' => 'dbtype',
'host' => 'localhost',
'port' => '3306',
'name' => 'dbname',
'user' => 'dbuser',
'pass' => 'dbpass',
'table' => 'dbtable'

We currently recommend using a SQL server, but more options will be available in the future.

Variables - variables.php

MogulMVC allows you to define global variables to be used throughout the application at a very low level of the application run process. Global variables are created shortly after the core libraries are in included but before the desired controller is instantiated.

To create a global variable open the variable file and add a global variable as you normally would in PHP.