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


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 🙂

Drupal 7: How to get user’s IP or hostname ?

In Drupal 7 how to find out any guest user or registered user’s IP address or hostname?

The answer is we can use session_id() which is stored in the ‘session’ table in the D7. It can return current user’s IP address or hostname by using session-id whether user is a guest or registered member.
So I write a function you can find it here.

[Opencart] Url Alias extension for SEO

This is an extension for opencart. User can add, edit or delete any SEO friendly url for their site. For your informatin this is my first MIT License opencart extension. If you find this usefull or any bug please let me know through this post.


Contributor: “Tanveer Noman”<>
Tags: cms, opencart, url, alias, seo
Requires at least: or later
Tested up to:
Stable tag: url alias
License: This content is released under the ( MIT License.

Click to Download

This extension is under CMS PACK for opencart store. User can create any desired SEO friendly url alias with this. Very easy to use. What you need just go to the “Url Alias” from Extension and then insert, edit or delete any alias.

Copy cms folder to it’s desired folder in the admin section. You need to change some files also (as vqmod is not currently available). But I can assure you it will provide soon. Download from here

Step 1: Backup all your data and source code.

Step 2: Login to admin panel. Go to System > Settings. Click “Edit” of your store. Select “Server” tab. Select “Use SEO URL’s” -> Yes and save.

Step 3: Go to your root folder and rename the file .htaccess_text to .htaccess. These lines of this file should be uncommented.

RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^download/(.*) /index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

Step 4: unzip file. Copy cms folder as per belonging folders like controller, language, model, view.

Step 5: Upload ‘vqmod/xml/admin_menu_modification.xml’ file to vQmod xml directory.


Step 5: If you don’t have vQmod right now, You need to edit these following files

//File: admin/controller/common/header.php 
//search this line 
$this->data['text_product'] = $this->language->get('text_product'); 
//add after that line
$this->data['text_url_alias'] = $this->language->get('text_url_alias');
//search this line 
$this->data['product'] = $this->url->link('catalog/product', 'token=' . $this->session->data['token'], 'SSL');
//add after that line
$this->data['url_alias'] = $this->url->link('cms/alias', 'token=' . $this->session->data['token'], 'SSL');
//File: admin/language/english/common/header.php 
//search this line 
$_['text_product']                     = 'Products';
//add after that line
$_['text_url_alias']				   = 'Url Alias';
//File: admin/view/template/common/header.tpl
//search this line 
<li><a href="<?php echo $feed; ?>"><?php echo $text_feed; ?></a></li>
//add after that line
<li><a href="<?php echo $url_alias; ?>"><?php echo $text_url_alias; ?></a></li> 

Upcoming Modules

* Form Manager: Create and add any form you want to any page in your store.
* Menu Manager: Manage your admin menu right away.
* gFeed Manager: Google Spreadsheet synchronization with opencart. It can load categories, manufactures, products from google spreadsheet.
* Report Manager: Manage your sells, quick view and generate report
* Ad Manager: Advertise products via SMS, Email and ad server

Help and Support
If you have any comments,feedback and or need any help to use this extension please comment below

Fork in Github
If you want to contribute you can fork here

1.0.1: resolving “text_url_alias” shows when user in the dashboard
1.0.2: vqmod xml file has been added to show ‘Url Alias’ menu item under Extentions admin menu


Take a line from a song that you love or connect with. Now forget the song, and turn that line into the title or inspiration for your post.

[OpenCart] how to install vQmod in OpenCart ?


Today, I came up here to make some easy pictures to install “vQmod” (Create xml patches for php files without editing the core system source code so called Virtual file modification system) in OpenCart

If you don’t know what is vQmod? then please read before we start.

vQmod: Virtual file modification system

Assume, we have installed a fresh copy of OpenCart in the system

In this tutorial there are more than one way that vQmod can be installed in the opencart system.

Install vQmod in OpenCart manually:

Step-1: For self securitey! Backup or make a duplicate of your existing installed OpenCart files and folders in safe place.

Step-2: Download the latest version of vQMod

Step-3: Extract and upload the vqmod folder to root of OpenCart directory.

Step-4: Now, we need to modify two files. One is /index.php and another one is /admin/index.php file


//File: /index.php 
// Startup
require_once(DIR_SYSTEM . 'startup.php');

// Application Classes
require_once(DIR_SYSTEM . 'library/customer.php');
require_once(DIR_SYSTEM . 'library/currency.php');
require_once(DIR_SYSTEM . 'library/tax.php');
require_once(DIR_SYSTEM . 'library/weight.php');
require_once(DIR_SYSTEM . 'library/length.php');
require_once(DIR_SYSTEM . 'library/cart.php');
require_once(DIR_SYSTEM . 'library/affiliate.php');

Replace with,

// vQmod

// VQMODDED Startup
require_once(VQMod::modCheck(DIR_SYSTEM . 'startup.php'));

// Application Classes
require_once(VQMod::modCheck(DIR_SYSTEM . 'library/customer.php'));
require_once(VQMod::modCheck(DIR_SYSTEM . 'library/currency.php'));
require_once(VQMod::modCheck(DIR_SYSTEM . 'library/tax.php'));
require_once(VQMod::modCheck(DIR_SYSTEM . 'library/weight.php'));
require_once(VQMod::modCheck(DIR_SYSTEM . 'library/length.php'));
require_once(VQMod::modCheck(DIR_SYSTEM . 'library/cart.php'));
require_once(VQMod::modCheck(DIR_SYSTEM . 'library/affiliate.php'));



//File: /admin/index.php
// Startup
require_once(DIR_SYSTEM . 'startup.php');

// Application Classes
require_once(DIR_SYSTEM . 'library/currency.php');
require_once(DIR_SYSTEM . 'library/user.php'));
require_once(DIR_SYSTEM . 'library/weight.php');
require_once(DIR_SYSTEM . 'library/length.php');

Replace with,

// vQmod

// VQMODDED Startup
require_once(VQMod::modCheck(DIR_SYSTEM . 'startup.php'));

// Application Classes
require_once(VQMod::modCheck(DIR_SYSTEM . 'library/currency.php'));
require_once(VQMod::modCheck(DIR_SYSTEM . 'library/user.php'));
require_once(VQMod::modCheck(DIR_SYSTEM . 'library/weight.php'));
require_once(VQMod::modCheck(DIR_SYSTEM . 'library/length.php'));

Step-5: vQmod is now ready to use. Upload desired xml script to ‘vqmod/xml’ folder

Step-6: How this .xml file should look? For exampale we need to add a menu item “Homenet” under “Extension” menu in the admin panel. So we need to create a file named admin_menu_modification.xml in ‘vqmod/xml’ folder like;


#author: Tanveer Noman
#file name: admin_menu_modification.xml
#description: This file is demonstrating how to write a simple xml file to add new
menu item named "Homenet" in admin menu section
	<id>Admin Menu Modification</id>
	<file name="admin/controller/common/header.php">
			<search position="after"><![CDATA[$this->data['text_feed'] = $this->language->get('text_feed');]]></search>
			<add><![CDATA[$this->data['text_homenet'] = $this->language->get('text_homenet');]]></add>
			<search position="after"><![CDATA[$this->data['feed'] = $this->url->link('extension/feed', 'token=' . $this->session->data['token'], 'SSL');]]></search>
			<add><![CDATA[$this->data['homenet'] = $this->url->link('homenet/homenet', 'token=' . $this->session->data['token'], 'SSL');]]></add>
	<file name="admin/view/template/common/header.tpl">
			<search position="after"><![CDATA[<li><a href="<?php echo $feed; ?>"><?php echo $text_feed; ?></a></li>]]></search>
			<add><![CDATA[<li><a href="<?php echo $homenet; ?>"><?php echo $text_homenet; ?></a></li>]]></add>
	<file name="admin/language/english/common/header.php">
			<search position="after"><![CDATA[$_['text_feed']                        = 'Product Feeds';]]></search>
			<add><![CDATA[$_['text_homenet']                     = 'Homenet';]]></add>

Wallah! You are done!

Step-7: Now log in to admin panel. Mouse over to “Extension” menu item, if everything works good then you can see a new menu item “Homenet” is added whithout changing any core system files.


Install vQmod in OpenCart using Autoinstaller:

Step-1: Download the latest version of vQMod and extract it.
Step-2: Use your FTP to upload the folder “vqmod” to your opencart store. Make sure vqmod/vqcache folders are writable (either 755 or 777).
Step-3: Now browse
Step-4: If everything goes well, you should get a success message. If not then check permissions.

– Make sure you are giving the currect vqmod path like; require_once(‘../vqmod/vqmod.php’);
– Check if the vqmod folder and the vqmod/vqcache folders are writable (755)
– Verify that there are new “vq2” files in the “vqmod/vqcache” folder after loading your store homepage
– Some times you may need to create “mods.cache” file inside “vqmod” folder and make it writable (755)
– You may need to create logs” folder inside “vqmod” folder and make it writable (755)

For more information:

Related Links:

That’s all!

You can inbox me or drop your comments/feedbak here I will reply on that regards.

Thanks for reading and don’t forget to share!

%d bloggers like this: