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 🙂

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.

https://github.com/tanveer-noman/neeocis-wp-support/tree/master/drupal-how-to-get-hostname

[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.

logo.1

CMSPACK :: URL ALIAS
Contributor: “Tanveer Noman”<tanveer.noman@gmail.com>
Blog: neeocis.wordpress.com
Tags: cms, opencart, url, alias, seo
Requires at least: 1.5.5.1 or later
Tested up to: 1.5.5.1
Stable tag: url alias
License: This content is released under the (http://opensource.org/licenses/MIT) MIT License.

Click to Download

Description
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.

Installation
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 CMSPACK.zip 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.

Or,

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

//1.
//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');
//2.
//File: admin/language/english/common/header.php 
//search this line 
$_['text_product']                     = 'Products';
//add after that line
$_['text_url_alias']				   = 'Url Alias';
//3.
//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
https://github.com/tanveer-noman/oc-cms-url-alias

Changelog
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

Inspiration

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 ?

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 1.5.5.1

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 1.5.5.1 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 vqmod-x.x.x-opencart.zip 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

Search,

//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
require_once('./vqmod/vqmod.php');
VQMod::bootup();

// 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'));

and,

Search,

//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
require_once('../vqmod/vqmod.php');
VQMod::bootup();

// 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;

‘vqmod/xml/admin_menu_modification.xml’

<!--
#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
-->
<modification>
	<id>Admin Menu Modification</id>
	<version>1.5.x</version>
	<vqmver>2.2.1</vqmver>
	<author>tanveer.noman@gmail.com</author>
	<file name="admin/controller/common/header.php">
		<operation>
			<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>
		</operation>
		<operation>
			<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>
		</operation>
	</file>
	<file name="admin/view/template/common/header.tpl">
		<operation>
			<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>
		</operation>		
	</file>
	<file name="admin/language/english/common/header.php">
		<operation>
			<search position="after"><![CDATA[$_['text_feed']                        = 'Product Feeds';]]></search>
			<add><![CDATA[$_['text_homenet']                     = 'Homenet';]]></add>
		</operation>		
	</file>
</modification>

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.

homenet

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 http://www.your-domain.com/vqmod/install
Step-4: If everything goes well, you should get a success message. If not then check permissions.

***Troubleshooting***
– 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:

http://docs.opencart.com/display/opencart/OpenCart+1.5+Home
http://www.opencart.com/index.php?route=extension/extension
http://forum.opencart.com
https://github.com/opencart/opencart/issues
http://opencart.hostjars.com
http://opencart-help.com

Related Links:
[Video] http://code.google.com/p/vqmod/wiki/Install_OpenCart

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!

[PHP] How to get longest string from array ?

Hope it will save your time. Sometimes in PHP we may need to find the longest string from an array. So you can get this solutions in google but I made a function to make it more usable. It will return maximum lenght, key and the string form that array.

Clieck Here to see the code

Don’t forget to share!.

Cheers!

[phpMyAdmin] How to enable Designer in phpMyAdmin

Some times we need to create ERD. In phpMyAdmin this can be done very easily. Just you need to change some configuration.

I am assuming that you have already installed phpMyAdmin (in my case it’s 3.4.3.2 version). You have to follow these simple steps;

Step 1: Open the file

libraries/config.default.php

Step 2: Find and change these configuration like this:

$cfg[‘Servers’][$i][‘pmadb’] = ‘phpmyadmin’;
$cfg[‘Servers’][$i][‘bookmarktable’] = ‘pma_bookmark’;
$cfg[‘Servers’][$i][‘relation’] = ‘pma_relation’;
$cfg[‘Servers’][$i][‘table_info’] = ‘pma_table_info’;
$cfg[‘Servers’][$i][‘table_coords’] = ‘pma_table_coords’;
$cfg[‘Servers’][$i][‘pdf_pages’] = ‘pma_pdf_pages’;
$cfg[‘Servers’][$i][‘column_info’] = ‘pma_column_info’;
$cfg[‘Servers’][$i][‘history’] = ‘pma_history’;
$cfg[‘Servers’][$i][‘designer_coords’] = ‘pma_designer_coords’;

Step 3: Now, create a database name phpmyadmin. You can copy and paste in these script.

Click to download phpmyadmin.sql

**NOTE: People are getting some unknown characters like ‘–’ and facing difficulties to load the SQL into the database. So I remove the SQL block form here and upload that in my github repository. Please download from there and accept my apologies for that.

you are done!

Step 4: Now select any of your database from the left side database list

Step 5: You will get a “Designer” tab

Step 6: Now, you need to logged out to phpmyadmin and then log-in again to be able to see the Designer tab. Click on the “Designer” tab and you will get something like this:

That’s all, you can now enjoy the model 😉

Updated suggest by:
– Meri Alvarado

%d bloggers like this: