DevBlog

Coding my way

3 years ago in PHP, simpleCMS · 2 MIN READ

simpleCMS – The basics

This article will be about the planning stage of creating your very own content management system.

The first and foremost thing about planning the project is to be consistent in the architecture. It doesn’t matter if it’s good or bad, once you decide something you stick with it (at least until the next major version)

In this example this project will utilize a basic autoloader function which will load our models and controllers, and a control handler which will match some of the functions to the corresponding template file, thus creating an output. This will be our framework/kernel/core of the project. The content manager will be built upon this base.

Our default structure will look something like this:

  • Project root
    • bower_components
    • cache
    • cms
    • controller
      • blog.php
      • page.php
    • model
      • blogModel.php
      • pageModel.php
    • vendor
    • view
    • front
      • blog
      • page
      • base.tpl
      • header.tpl
      • footer.tpl
      • home.tpl
    • admin
    • blog
    • page
    • base.tpl
    • header.tpl
    • footer.tpl
    • home.tpl
    • system
    • controller
      • coreFunctions.php
      • controlHandler.php
      • databaseHandler.php
      • modelHandler.php
      • smartyHandler.php
      • model
      • router.php
    • .htaccess
    • autoloader.php
    • config.php
    • index.php

From the directory structure we’ll see that there are separate folders for the cms parts and the system parts. This is only for visibility in the development, this can be also more refined with an app folder that can contain all the client specific additions, or you can throw everything into one folder, and be done with it. It’s usually good practice to group the different types of classes in some logical way.

In the next articles we’ll build up the framework, but for now let’s go through the basic structure.

The bower_components folder will contain all the dependencies added through the bower dependency manager.

The cache folder will hold all the cached elements, like the smarty template cache, image cache, and so on… If the caching causes any troubles or you need to rebuild the cache for some reason it’s easier to have it in one place.

The cms folder will contain the controllers and models that aren’t part of the framework, like compiling the views, managing form saving, and so on…

The vendor folder will contain all the dependencies added through the composer dependency manager. This also includes an autoloader for all the dependencies, so you only have to include that one file.

The view folder will contain all our template files. Maybe you noticed some matches between the class names and the sub-folders in the view folder. That’s because how our controlHandler will work. It will check the url, for a class and function name to be loaded, for example> if the url is localhost/blog/view/test-post.html, then the controlHandler will check if the blog class has a view method, also it will check that a corresponding template file exists in the view (in this case in front folder), and if both exists it will render the page, else it will throw a 404 error

The system folder, is where all the magic begins. It will contain our little framework that will handle the url to logic translation, the database magic, it will be the store house of all the nifty little functions that will make the subsequent cms development and extension as light as a breeze.

In the next article I’ll provide the basic framework that’s required to make things work, but it’s up to YOU to take it wherever you want

···

Miklós Galicz

I'm a hobbyist who managed to become a professional web developer who specializes in Laravel and Vue.js, also the Spice must flow.
comments powered by Disqus


© 2017 DevBlog