Create your own PHP framework using MVC design pattern (Part – 2)

Ok!, at last I have finished creating my own MVC PHP framework. I named is Sp!ce (spice). I think you guys will get lot’s of fun using this framework. So let’s start.

If you didn’t read Part-1 then please do that before continue.

Step 1: Folder Structure

I think folder structure is really important. So we need to fix that first. In my opinion, ROOT folder need to settle down with these following folders

spice-framework

Step 2: We are now create the .htaccess file. In this file we will use `mod_rewrite.c` apache module and need to prevent file browsing option by using “Options -Indexes”. So our .htaccess file should be look like this

click here to see .htaccess file

Step 2: Now we need to create our index.php file. In this file all we need to load controller, model and view classes and off course configuration and start up file.

click here to see index.php file

Step 3: Now you can see I have created a folder system because this folder will collect all the system files like config.php file along with model, view, controller classes that I have created. startup.php  is holding a function that will check every URL that pass through by browser and let the system know which controller will need to fetch and pass. Before digging more into that we will need to know more about the config.php file. We need to set the database related global variables like database host name, user name, password and the server host.

click here to see config.php file

Step 4: Our last goal is to create a startup.php file. This is the file where each and every URL that need to pass to the browser via index.php file. This file will check whether it goes to custom controller or default controller.

click to see startup.php file

Step 5: Download the full source code. I have created a small project named ‘addressbook‘ by using spice framework. There is also a mysql database dump file. You need to  process these follow these steps:

click to download full source code

1. Go to phpmyadmin and create a database named `spice`;
2. Now import the `sql/spice.sql` file to the database.
3. Go to system/config file. You need to set base url like `http://localhost/spice/` or what you might feet.
4. Now set the database host. Usually it’s `localhost`, database name is `spice` or the name you have created, the user is the database user name and set the password.

Your done!

GO TO the browser and then visit your site.

Let me know if you have any confusion, comments or feedback. I will really appreciate that to improve the framework. If anyone wants to contribute please click here.

Read this book Learning PHP, MySQL, JavaScript, CSS & HTML5: A Step-by-Step Guide to Creating Dynamic Websites to learn more on PHP.

Enjoy 🙂

Advertisements

About Tanveer
RIA (Rich Internet Application) Developer with a wide variety of business applications. Particularly interested in client/server and relational database design. Always interested in migration projects, as well as close interaction with the DB manufacturers.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: