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:

25 Comments to "PHP Framework Introduction"

Franco Rinaudo

Franco Rinaudo / December 3, 2023 at 18:45 pm

I have just bought the MegaSale pack. It seems that the same development license is of application for the pack. I would like to use my own logo and link. Where in a package (i.e. PHPpoll script) can I do these modifications?

Wilfred Aasheim

Wilfred Aasheim / November 1, 2022 at 07:27 am

Can anybody show me how I modify my Availability Booking Calendar script in order to make the transition from PHP Version 7,4 to Version 8.0. My web provider has upgraded PHP, so now my calendar script no longer functions. And I have no experience with this.

Angelos

Angelos / September 15, 2022 at 14:08 pm

Hi,
is it possible to get the functionality index.php?controller=pjAdminUsers&action=pjActionIndex provides without using controller and action parameters in the url?

As an example from:
domain.com/index.php?controller=pjAdminUsers&action=pjActionIndex
to:
domain.com/users

Tahir Ali

Tahir Ali / June 13, 2021 at 23:59 pm

Hi. Can you write a simple sql query
Select id, name from table1 where table1.Name =table2.Name

guntherr

guntherr / December 22, 2019 at 01:59 am

I dont find two features to change in the pet listing script.
1. Can't find to remove the header tekst and change it into my one.
2. Can't add the role called owner
Please help, i was reading the script code but cannot find these issues.
Gunther

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