Skip to content

System Structure

cryptonaut420 edited this page Mar 15, 2015 · 11 revisions

##Framework

Tokenly CMS uses its own basic PHP MVC framework, tentatively called Slick Framework. Slick is quite simple and primarily consists of base configuration, a class autoloader, a database wrapper and a collection of helper classes and libraries. Most of these files are located in /www/slick

####Autoloading

The autoloader allows us to call functions that may be included in other files, but not have to explicitly call something like require_once(my_file.php) every time. The autoloader can be used alongside other autoloaders (perhaps with an alternative framework or system), however it will load any classes which fit the correct pattern and have an existing file.

Classes follow a naming structure that looks like this: Slick_Core_Model.

The name of the class tells the autoloader where it is located. Each word separated by an underscore is translated into a directory or sub-directory, and the last word is the full name of both the file and the class.
So Slick_Core_Model translates to the path /www/slick/core/Model.php which itself contains
<?php class Slick_Core_Model

Not all classes necessarily need to start with "Slick_", that just dictates the starting path. You could just as easily have a class called Custom_Models_Account which would load /www/custom/models/Account.php.

####MVC

MVC stands for "Model, View, Controller", and is the style of choice for code architecture in Tokenly CMS. The basic idea is a separation of duties for your code, keeping the request/control, data processing and output logic distinct from one another. This helps in keeping things extendible and maintainable. You can learn more about these concepts here

Typically, most features are organized into their own folders or modules, and contain at least a Controller.php and a Model.php file, as well as sometimes a View.php or set of view files in the themes folder (more on that shortly).

Models
These files are where most of your data processing and database calls should live. Things such as grabbing lists of data from the database, manipulating that data or parsing it in preparation for display/output to the user.

Any model class which interacts with the MySQL database should extend off of Slick_Core_Model, which is our database wrapper class. Click here to learn more about database interaction.

Views
view files are where display logic and specific HTML output are stored, usually using data obtained from models.

Controllers
A controller is the file that handles the URL request, loads the models, figures out what to do with the request data and spits out a response, usually in the form of passing data to and displaying a view file or invoking a page redirect.

##App System

This is where the meat of the system really begins.

Our journey starts on www/index.php...

<?php
require_once('../conf/config.php');
include(FRAMEWORK_PATH.'/autoload.php');
session_start();
ob_start();
$app = new Slick_App_Controller;
$app->init();
$outputSite = trim(ob_get_contents());
ob_end_clean();
echo $outputSite;

First, the configuration file is loaded which contains the base folder paths, database credentials, etc. Next, the autoloader is included in and both browsing session and output buffers started. A class called Slick_App_Controller is loaded and initialized. Finally, the outputted result of that initialization is captured, buffer ended and final results/content displayed.

The App Controller is where most of the magic happens. There is a fair amount going on here, but basically when the $app->init() function is called, it takes the following steps:

  • Parses the request URL into a series of arguments/parameters (example.com/app/module/param1/param2)
  • Checks and loads data from the DB for this particular website domain
  • Checks to see if system is in maintenance mode or not
  • Loads system settings and user account info (if logged in)
  • Compares the parameters obtained from the request URL against the list of Apps & Modules as well as the Page Index. Looks to see if the URL matches up to any possible locations (and the user has appropriate access permissions), otherwise a 404 not found (or a 403) error is displayed.
  • Loads an instance of the appropriate App and passes relevant data to it, then calling its init() function.
  • Takes the data results from the App and passes it into the class Slick_App_View via calling $view->load($data). This is what outputs the final response / HTML to the end user.

Let's go over a few specifics:

####Domains

The CMS allows for multiple websites to operate under a single system installation, which is also sometimes referred to as sub-sites. In order for it to load the appropriate theme, pages, content etc., the domain name it is being accessed from must match up to an entry in the sites database table. The domain field in the sites table should look like example.com (no http://, "www." or other parameters), while the url field should be like http://example.com (the full URL, used for redirects).

####URL Structure

Most URLs in the system are in the simple format /{app_slug}/{module_slug}/param1/param2.... For example, a URL for editing a forum thread might look like /forums/post/my-first-topic/edit.

In addition to this standard structure, there is also the Page Index. This allows for completely custom URLs to be used, which can point to and load any app/module/parameter combo. For example, you could have a URL of /ltb-special-episode which loads a blog post as if you went to /blog/post/ltb-special-episode. This feature is primarily used for simple CMS Pages, but can also be useful for such things as saving old links for content imported in from a different system (e.g importing WordPress posts but keeping the links the same).

####Apps & Modules

The Tokenly CMS uses the concepts of Apps and Modules for how specific features and functionality within the system are organized. An App is basically a set or group of features, while a Module is usually a specific component or feature within that.

For instance, Forum and Blog are two individual Apps, and within them they each have their own modules such as Boards, Post and Category. All Apps are located in the folder /www/slick/App.

Click here to learn about this in further detail.

####Views & Themes

##Folder Structure Overview

Clone this wiki locally