go top

MEGA Sale

  • Colection of 65 PHP scripts for $4.29 each

Get 65 PHP scripts in a bundle for $4.29 each!

View Offer

PHP Framework Introduction

by Dimitar Ivanov /  Updates & Releases

As we continue to update our products, most of them are now using the same framework based on the MVC model.  The MVC model is a method to develop a software in three parts - Model, View and Controller (MVC). The Model is the part where logic is defined, for example the type of fields that user has - name, email, phone, last login, unique ID, etc... The View part is the output of the software. These are the layouts and templates. The Controllers is where the magic happens – the code in the controllers accepts the input, manipulates the data and sends back all the output to the “views”. As you can imagine this makes it super easy even for a non experienced person to make small changes to the code. If for example you need to change the front end layout you only have to work with “views” and there is no need of more complex code in the controllers.

 

You can find all PHPjabbers' scripts that currently support the new framework at the bottom of the "One admiN" presenation page.

 

Now lets talk about folder and file structure. I will present some general information about how files and folders are organized. In the upcoming weeks we will also post another articles related to different parts of the PHP framework - components, plugins, creating SQL, how multi lang is organized, etc..

 

Root folder

In the root folder you will see two sub-folders /app/ and /core/.

App and core folders in file explorer

 

The /app/ folder is where all the specific files are located - models, controllers, views, options, plugins, css, js, data files, etc.. If you need to make a change to any part of the script - functionality or design - this is the folder where you should look. We will discuss it later in the post.

 

The files in the /core/ folder are code libraries that are used by our scripts. Instead of writing the same piece of code multiple times we’ve created a code library for these repeatedly used functions. For example we have pjEmail.component.php which is used to send emails. Of course it handles mail() and SMTP methods, file attachments, multiple recipients, etc.. which makes the PHP code used very long. To avoid writing the same long PHP code for sending an email when an email has to be sent we just call a function defined in that pjEmail.component.php file. This saves a lot time writing the code, studying it and modifying it. This is a very productive way to code because if you ever need to make a change to the mail sending code you need to update it in one place only - the email component file.

 

In the /core/ folder there are also folders for external libraries (such as jQuery, TinyMCE, et..).

 

There are also a couple of obfusticated files which as per our license agreement you cannot change. These files are used to process and manipulate the data on a low level so as long as you understand the MVC model logic you will not need to do any changes to them anyway. 

 

The /app/config/ folder

PHP scripts and an SQL file inside an application configuration folder

 

In that folder you can find script configuration files. When you install the product, the config.inc.php file is generated together with all the necessary information in it - MySQL login details, server installation path and URL. So if you ever decide to change the MySQL database password for your server you need to open config.inc.php file and change the password there too. Please, note that before you install our product, this config.inc.php file is empty (0 bytes). Also depending on your server configuration, write permissions to it may need to be set. This is of course checked by our installer wizard and you will be notified if such permissions need to be set.

 

There is also database.sql file where all the SQL queries to set up the script are stored. So when you make a fresh installation and run the installer it will execute all the queries found in this file.

 

The /app/models/ folder

PHP scripts inside an application model folder

 

You can find all models for our software in /app/models/ folder. There you can see a different file for each of the product’s specific features. A model that is pretty much the same for all our products is pjUser.model.php.  In that file we have the fields defined for each user plus the type of these fields, their default values and validation types. This is basically a PHP class which defines the data type. So if you decide to add a new field for your users one of the places where you should add it is the model file.

 

The /app/controllers/ folder

PHP scripts inside an application controllers folder

 

In this folder you can find the controllers for the product. These are the files which process all the data. There is a different controller file for each product element. For example the controller for managing user accounts is pjAdminUsers.controller.php

 

Within the file you will find different functions which are used to manipulate the data. A typical functions would be

  • pjActionCreate() - to create a new user
  • pjActionUpdate() - to update an existing user
  • pjActionDeleteUser() - to delete an user

 

As you can see we have named the functions in an easy to read format. So when you see a function such as pjActionExportUser you will know that it is used to export user(s) details.

 

The /app/plugins/ folder

Sub-folders inside an application plugins folder

 

In this folder you can find different plugins that are the same for the different products that we have. For example pjOneAdmin is a good example for a plugin which works the same way in all our products. Each plugin is built using the MVC model and consist of models, views and controller files.

 

The /app/views/ folder

Sub-folders and a PHP script inside an application views folder

 

Here you can find all the web page templates - or so called “Views” in the MVC model. So if you want to change the layout of a particular page you need to look into this folder. As you can see the folders and file names are named in an easy to read format so you can easily understand what each file is about.

Lets open the “pjAdminUsers”. By its name you can imagine that there you can find the page templates used for managing user accounts - list, add, edit pages. You will see these files in the folder.

PHP scripts inside the pjAdminUsers folder

 

  • pjActionCreate.php - this is the template for the create new user page
  • pjActionIndex.php - this is the template for the list all users page
  • pjActionUpdate.php - this is the template for view and edit user pages

 

The /app/web/ folder

The last folder is the /web/ folder. If you open the folder you will see that there are different subfolders where all JavaScript and CSS styles are stored. There are also a couple of folders used by the plugins - backup, invoice, etc. If the product that you use lets you upload images (for example Vacation Rental script where you upload images for each property) then you will have /uploads/ sub-folder where these images will be uploaded.

 

URL structure - views and controllers

The index.php file in script root folder is the file which processes all the information. Both the backend and front end are loaded through that file but depending on the parameters passed different information is shown. The format of the URL gives you a lot of information about what the controller and views are used. For example when you are logged into the administration page and go to Users page the URL in your browser will be as shown below:

index.php?controller=pjAdminUsers&action=pjActionIndex

 

Analyzing the URL structure you can find that:

  • the controller file you should be looking at is /app/controllers/pjAdminUsers.controller.php
  • the PHP function which is called to generate all the content you see on that page is in the pjAdminUsers.controller.php file and is called pjActionIndex()
  • the web page template file is /app/views/pjAdminUsers/pjActionIndex.php

 

If you go to Edit user page the URL will change to:

index.php?controller=pjAdminUsers&action=pjActionUpdate&id=1

 

and hence:

  • the controller file is still /app/controllers/pjAdminUsers.controller.php
  • however the PHP function is now pjActionUpdate()
  • and the web page template file is /app/views/pjAdminUsers/pjActionUpdate.php

 

I hope this article is a good starting point for you to study and use our MVC framework. You may also check this page for details about MVC. Thank you for reading!

Share on:

26 Comments to "PHP Framework Introduction"

Ghislain MAMAT

Ghislain MAMAT / August 24, 2016 at 14:21 pm

How can I download code source

Florian Vlad

Florian Vlad / August 6, 2016 at 11:08 am

Hi,

Well we have a website on laravel mvc framework. Would the best option be to make this script as an api? do you have some ideas for this?

Sasho Valkanov

Sasho Valkanov / August 8, 2016 at 10:15 am

The easiest way to integrate the script is to use its JS code. However, if you want to integrate the actual database and backend within existing framework you will have to write your own code to read/write from/to script database.

Alex Bobeica

Alex Bobeica / August 5, 2016 at 18:31 pm

Hi,
How can I integrate this package, for example time slot booking calendar, with another php mvc framework, laravel for example?

Regards

Sasho Valkanov

Sasho Valkanov / August 6, 2016 at 10:38 am

Can you please elaborate on what you try to achieve. Our products are made using our framework and "switching" to another framework is equal to doing them all from scratch.

Chris

Chris / June 30, 2016 at 01:32 am

I am trying to add an anchor to the links in the script so that when it gets called, the script stays in the same panel (the script is loaded in a panel and right now when an action is called (login, add file, etc) it reverts the panels back to the opening one. I am using your file share script and was able to change the forgot password, but the other links seem to evade me. Is there any help you could offer?

Sasho Valkanov

Sasho Valkanov / June 30, 2016 at 09:38 am

It seems you are having problems with submitting the forms. I am afraid you will have to do lots of code changes to make the forms submit in the panel without refresh. You may look at this answer on stackoverflow

http://stackoverflow.com/questions/11319212/submit-html-form-data-to-a-div-element-without-refreshing-a-page

Prasad

Prasad / March 19, 2016 at 07:17 am

I am modifying database.sql file in orders table and installed it. It won't work at dash board for ordering any product it gives jquery error

Add your comment

Captcha

    Please, be polite and helpful and do not spam or offend others! We promise you will be treated the same way!

    Log in to your account to post your comments. If you still haven't joined our community yet, you can create your FREE account now!

    Posting tip:
    If you use code in your comments, please put it in these tags [php], [sql], [css], [js] PHP code example: [php] echo date("Y-m-d"); [/php]

    Thank you,
    PHPJabbers Team