June 1, 2018

How to build Simple and Most Easy PHP MVC Framework for All Beginner/Pro DEVELOPERS

When it comes to building real web application we have to go through some certain level of programming to help us achieve this. We have to put into consideration the way we want our applications to be and the way other's will see it.




This Topic will help you a long way to build a PHP MVC if you have been finding it difficult to build for long.



before we begin lets Know what is PHP MVC:



PHP MVC is an application design pattern that separates the application data and business logic (model) from the presentation (view). MVC stands for Model, View & Controller. The controller mediates between the models and views.



I know sometimes we build web apps and we think of how to make a better URL patter like say we don't want to have a post ID on the link and this will help you a long way to understand it also.





Our folder structure:

app
config
controllers
core
includes
libs
models
views
css
js
public

The Above is our folder structure, Please have it in mind am not using the php autoload function (spl_auto_register) for easier understand am still going to develop it in the future for commercial use also.

am just going to drop you some of the codes and you can download the source code:

htaccess

RewriteEngine ON
RewriteBase /samuelmvc/ #change this to your own folder name

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(config|core|css|js|fonts|robots\.txt)

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]


After Downloading the source_code file your will see a code like the below in the app/libs folder

    $url = isset($_GET['url']) ? explode("/", ltrim($_GET['url'], '/')) : [];

  I made it so easy i have not finish the documentation on my next post on MVC for php i will make everything clearer. Please bear with me for now





Download Source Code.zip , DEMO



No comments:

Post a Comment