Category Archives: PHP Frameworks

Install Zend Framework on Shared hosting server

zend-framework-on-shared-hosting-server

If your site is hosted on Shared Server and you want to use Zend library on your project.

 

For Dedicated server, you have full root access and can have remote or full putty access of your server, you can install/uninstall any library as well as software in the server.
The same will be done by Server Guy on your request.

 

But, in this case “Shared hosting”, you should handle these either by using .htaccess file or by overriding the php.ini file, let see how you can do this.

 

If you need to install Zend framework what you should do is.

 

1. Check the document root path of your server.Use phpinfo(); php function for check.

<?php
echo phpinfo();
?>

The below is the sreengrab of my local system, the path will be different for your server.

XAMPP_Document_Root_PATH_PHPinfo

 

 

2. Upload Zend library into your hosting server (path : root/library/Zend)

 

3. Create or update your php5.ini (If you are using php5, use php5.ini file) or php.ini file.

put this line, (If you already have, add this line end of the current set, connected with ‘:’)

include_path = [DOCUMENT_ROOT]/Zend Libraray Path

ex) include_path = /home/scriptarticle/public_html/library

 

It’s Done !!

Now test whether the zend installed well or not, let’s echo the Zend frame work version.

 

<?php
require_once 'Zend/Version.php';
echo 'Zend Framework Version : ' . Zend_Version::VERSION;
?>

 

If you see your Zend version, that means your Zend framework has been installed successfully!

 

Save

PHP Object cloning using clone keyword and __clone() magic method

object-clone-php

Object cloning or clone of an object means to create a duplicate of an object.
With regular variables $var1 = $var2 means that a new variable $var1 created and have the value of $var2 that means 2 variables created.

 

With objects $obj2 = $obj1 does not mean that a new object i.e. $obj2 get created.

 

When we execute $obj2 = $obj1, the reference of $obj1 is assigned to $obj2. This means that $obj1 and $obj2 point to the same memory space.

So assigning other variables to an object will not actually copy the object, it will simply create a new reference to the same object. In order to truly copy an object, we must use the clone keyword.

<?php

class House {
	private $room_name;
 
	public function setRoomName($room_name) {
		$this->room_name = $room_name;
	}
 
	public function getRoomName() {
		return $this->room_name;
	}
}
 
$obj1 = new House();
$obj1->setRoomName("Bedroom");
 
$obj2 = $obj1; //only reference or memory assigned
 
$obj2->setRoomName("Dining Room");
 
echo $obj1->getRoomName();
echo $obj2->getRoomName();

?>

Both will return “Bedroom”

Therefore, to create a new $obj2 object we must “clone” an object to create a new object.

<?php
	$obj2 = clone $obj1;
?>

 

After the above line is executed $obj2 with a new memory space is created with the data members having the same value as that of $obj1. This is also referred to as shallow copy.

 

However, this technique will not work with a class that has a data member which is an object of another class (i.e object of an object technique is used). In such a scenario, the cloned object continues to share the reference of the data member object of the class that was cloned.

 

For resolving this we need to use the concept of ‘deep copy’ as opposed to ‘shallow copy’. To implement this you should implement the magic method __clone().

<?php

class House {
	private $room_name;
 
	public function setRoomName($room_name) {
		$this->room_name = $room_name;
	}
 
	public function getRoomName() {
		return $this->room_name;
	}
 
	public function __clone() {
		$obj = new House();
		$obj->setRoomName($this->room_name);
		return $obj;
	}
 
}
 
$obj1 = new House();
$obj1->setRoomName("Bedroom");
 
$obj2 = clone $obj1; //new object $obj2
 
$obj2->setRoomName("Dining Room");
 
echo $obj1->getRoomName();
echo $obj2->getRoomName();

?>

 

So, the __clone() magic method allows developers to implement a deep copy of an object when it is cloned.

PHP first performs a shallow clone and the calls the __clone() method on the new object, if it exists, to complete the cloning process.

 

PHP Magic Predefined Constants & usages

magic-php-predefined-constant

PHP Magic Predefined Constants & usages

In PHP, a constant is a name or an identifier for a simple value. A constant name starts with a letter or underscore can be followed by any number of letters, numbers, or underscores. If you have defined a constant, it can never be changed or undefined.

 

You have to use define() function to put value in the constant and for retrieval the value simply specifying the name.
The constant() function can be used if you create the constant name dynamically and want to fetch the value of the constant.

 

<?php
define("SITENAME", 'scriptarticle.com');
echo SITENAME;
echo constant("SITENAME"); // returns the same as previous one
?>

 

Along with the above PHP itself have a lot of predefined constants.

Some of the constants that are specials and can be called as magical are listed as below with example, these starts and ends with double underscore (__) and written in capital letters.

The predefined constants are very useful to access information about your code.

 

__LINE__

returns the line number in the code where the constant appears.

 

__DIR__

represents the path to the current file.

 

__CLASS__

returns current class name.

 

__FUNCTION__

returns current function name.

 

__METHOD__

represents the current method name.

 

__NAMESPACE__

returns the current namespace name.

 

__FILE__

represents the name of your file, includes its full path.

 

I have included all these in the below example, have a look.

<?php

	// Set namespace (works only with PHP 5.3 and later)
	namespace Scriptarticle;

	// this echo current file's full path and name
	echo "This file full path and file name is '" . __FILE__;

	// this echo file full path
	echo "This file full path is '" . __DIR__;

	// This echo current line number on file
	echo "This is line number " . __LINE__;

	function function_magic_constant() {
		echo "This is from '" . __FUNCTION__ . "' function.";
	}

	// echo function and used namespace
	function_magic_constant();

	class SAConstants {
		// echo class name
		public function printClassName() {
			echo "This is " . __CLASS__ . " class";
		}
		// echo class and method name
		public function printMethodName() {
			echo "This is " . __METHOD__ . " method";
		}
		// echo function name
		public function printFunction() {
			echo "This is function '" . __FUNCTION__ . "' inside class";
		}
		public function printNamespace() {
			echo "Namespace name is '" . __NAMESPACE__ . "'";
		}
	}

	// create a object of the class
	$obj = new SAConstants;

	$obj->printClassName();

	$obj->printMethodName();

	// this prints function name inside class and used namespace
	// same as method name, but without class
	$obj->printFunction();

	// this prints namespace name
	$obj->printNamespace();

?>

 

If you want to view a complete list of PHP predefined constant then follow the below links.

PHP Config Predefined Constants
PHP Image Predefined Constants
PHP Date Predefined Constants
PHP Core Predefined Constants
PHP Magic constants

 

Hope you have enjoyed the post!!

 

What is a WordPress Child theme & how to customize WordPress Theme using WordPress Child theme?

wordpress-child-theme-customize

We all know that a WordPress theme is a collection of template files which lets us change the user interface, design, look & feel of the site.

 

Have you created WordPress theme or have installed any free theme or commercial one, many of you have done this job and have also customized but the problem is created when you have customized the original theme files and the update of that theme is available and you never would like to update as your customization will get destroyed if you update that, but my recommendation is that you should always keep your plugins and themes updated to the latest version. So you should take care during the customization and never do the customization in original file and should create a child theme. But what does that mean, and how do you do it?

 

In WordPress 3. 0 or latest versions a new concept was added by WordPress core team and community named as “Child Theme”.

 

As per the WordPress Codex definition of Child Theme:

 

“A WordPress child theme is a theme that inherits the functionality of another theme, called the parent theme. 

Child theme allows you to modify, or add to the functionality of that parent theme. A child theme is the safest and easiest way to modify an existing theme, whether you want to make a few tiny changes or extensive changes. Instead of modifying the theme files directly, you can create a child theme and override within. “

 

How to work with WordPress Child Theme?

 

Let’s take an example; I’ll create a child theme for WordPress default ‘Twenty Twelve’ theme.

1) So in this case, to create a child theme, I have to create a new directory alongside the ‘Twenty Twelve’ theme’s directory called twentytwelve-child.
“twentytwelve-child” directory should be in parallel of original theme twentytwelve.

2) Create a style.css file under the ‘twentytwelve-child’ theme directory.

Put the below text in style.css file

/*
Theme Name:     Twenty Twelve Child
Theme URI:      http://wp. tutsplus.com/
Description:    Child theme for Twenty Twelve
Author:         Japh
Author URI:     http://wp. tutsplus.com/author/japh
Template:       twentytwelve
Version:        1. 0. 0
*/

// This @import line loads the stylesheet of parent theme
@import url('. . /twentytwelve/style.css');

//Theme customization starts here

There are two important parts here to notice:

Template: twentytwelve
It tells WordPress that this theme is a child theme of the ‘Twenty Twelve’ theme

@import url(“. . /twentytwelve/style.css”);
It loads the parent theme’s (twentytwelve in this case) style.css as a starting point

3) Now you can log into your WordPress dashboard and see your ‘Twenty Twelve Child’ theme there, and activate it.

4) Make further alterations & addition and you will found that these will automatically reflected on your website.

 

Just Done!!

 

Now always keep in mind that whenever you want to make a customization to your theme, does it in your child theme.

Files in your child theme override files of the same name in the parent theme. So any file from your parent theme you want to change, copy to your child theme & make your modifications there.

The same goes for any templates that may not be in your parent theme. You can add them in your child theme, and WordPress will use them.

One exception to these rules is the functions.php file. In this case, the functions.php file for the child theme is loaded first, followed by the functions.php file of the parent theme. So there’s no need to copy the functions.php file from the parent into the child, just start fresh in the child theme for that one.

This allows the child theme to have all the functionality from the parent theme. Parent themes can also make their function pluggable, which allows a child theme to override them.

 

Why should you use WordPress Child Themes?

 

1. Safe Updates

A child theme automatically inherits the parent theme’s features, styles, and templates. This allows you to make changes to your site using child themes without ever modifying the parent theme. When a new version of the parent theme available, you can safely update it as you know that all your modifications are saved in the child theme.

 

2. Easy to Extend
A child theme built on a powerful theme framework allows a great deal of flexibility without writing a lot of code. You can selectively modify only the template files and functions that you need without going through other template files. You can add new functionality and much more.

 

3. Fall-back Safe
When you are creating a complete theme you need to think about all the possible scenarios and code for them. However, when you are working on a child theme and you forget to code for something, then there is always the parent theme’s functionality available as the fallback option.

 

WordPress catchable Tools for Child Theme

 

One-Click Child Theme plugin built and tested for the latest WordPress 3.x version.It adds a menu link into your Admin “Themes” section to automatically build a child using your currently active theme.This is fantastic if you don’t want to mess with FTP and are looking to play around with some new ideas.You can also use Child Themify plugin for creating the child themes.

 

If you plan to edit these files within the admin panel you’ll also enjoy clearer syntax highlighting for that you can install the Advanced Code Editor for some much-improved functionality. This makes wading through PHP code blocks and HTML/CSS a whole lot more manageable.

 

Additional Resources & references

 

1. http://wp.tutsplus.com/tutorials/theme-development/child-themes-basics-and-creating-child-themes-in-wordpress/

2. http://www.hongkiat.com/blog/wordpress-child-themes-dev/

 

Hope this all helps.

 

what is difference between array_merge and array_combine in php

array_merge-array_combine-difference

Difference between array_merge and array_combine in php

 

Array Merge

PHP: array_merge
Merge one or more arrays

 

Merges the elements of one or more arrays together so that the values of one are appended to the end of the previous one.
If the input arrays have the same string keys, then the later value for that key will overwrite the previous one or if the arrays contain numeric keys, then the later value will not overwrite the original value and will be appended.

 

Values in the input array with numeric keys will be renumbered with incrementing keys starting from zero in the result array.

 

Have a look on example below

 

Example:
<?php
$array1 = array(“color” => “red”, 2, 4);
$array2 = array(“a”, “b”, “color” => “green”, “shape” => “trapezoid”, 4);
$result = array_merge($array1, $array2);
print_r($result);
?>

 

Output will:
Array
(
[color] => green
[0] => 2
[1] => 4
[2] => a
[3] => b
[shape] => trapezoid
[4] => 4
)

 

Array Combine

PHP: array_combine
Creates an array by using one array for keys and another for its values

 

Example:
<?php
$array1 = array(“green”,”red”,”yellow”);
$array2 = array(“avocado”, “apple”, “banana”);
$result = array_combine($array1, $array2);
print_r($result);
?>

 

Output will:
Array
(
[green] => avocado
[red] => apple
[yellow] => banana
)

 

PHP: Choose The Best Shopping Cart Software

best-php-ecommerce-solutions

PHP: Open Source E-Commerce Shopping Carts Software

Choosing right shopping cart software is one of the most crucial steps to making your on-line business successful.

 

A customer always needs to be able to purchase products as easily as possible, with a sense of security.

 

A business owners always choose software that should be simple to use with useful features and great customer support whenever needed and some marketing related tools.

The following are the general criteria that are generally used to evaluate the best shopping cart software.

 

Web Design

The design features of shopping cart software should include an array of design templates to choose from and step-by-step wizards or WYSIWYG editors for storefront development. The templates should be easy to use and should offer customization options that enable you to create the perfect site for your business.

 

Administration & Inventory Control

Shopping cart software includes a range of administrative features that allow you to manage your inventory. An administrative dashboard provides access to product upload, editing and management options. The best shopping cart software applications allow you to upload an unlimited number of products and sell both hard (physical) and soft goods (services or downloadable products, such as software).
Beyond inventory control, the best shopping cart software offers comprehensive payment options and integration with accounting software.

 

Marketing

Shopping cart eCommerce software should include robust marketing tools to help you generate more traffic to your site and thus increase sales. For instance, you should be able to automate abandoned cart emails, offer daily deals and implement a loyalty program for your shoppers. Additionally, the software should allow you to run detailed sales reports so that you can easily identify your best – and worst – selling products.

 

Security

Security is a chief concern for online shoppers, so it’s crucial to make sure that the shopping cart website you use offers standard security features. These should include fraud protection, SSL secure checkouts that encrypt customers’ payment information, as well as data backup and restoration to protect your business records.

 

Help & Support

The manufacturers of top-notch shopping cart software provide comprehensive support resources that you can reference, including a knowledge-base, community forums and video tutorials. The manufacturer should also provide direct technical assistance via email or telephone.

 

According to these criteria and popularity I am sharing the 10 Best Open Source Shopping Carts.

 

You can also view the popularity on Wikipedia link as below.
http://en.wikipedia.org/wiki/Comparison_of_shopping_cart_software

 

1) Magento

magento-logo

Magento is a feature-rich eCommerce platform built on open-source technology that provides online merchants with unprecedented flexibility and control over the look, content and functionality of their eCommerce store. Magneto’s intuitive administration interface features powerful marketing, search engine optimization and catalog-management tools to give merchants the power to create sites that are tailored to their unique business needs.

 

See more
Front: http://demo.magentocommerce.com/
Admin: demo-admin.magentocommerce.com/index.php
Username: admin Password: 123123

 

2) Prestashop
prestashop-logo

Prestashop is an award winning e-commerce solution having won the Best Open Source Business Application. Having been distributed under the open source license, Prestashop now powers thousands and thousands of online stores across the globe. It is also backed by an active community of developers who frequently develop various add-ons for extending the functionalities of Prestashop. Currently, PrestaShop has around 275 e-commerce features that make online business an easier and simpler affair for online merchants.

 

See more
Front: http://demo-store.prestashop.com/en/
Admin: http://demo-bo.prestashop.com/demo/index.php?controller=AdminLogin&email=demo@prestashop.com
Username: demo@prestashop.com Password: prestashop_demo

 

3) Open cart
opencart-logo

OpenCart is an open source PHP-based online shopping cart system. A robust e-commerce solution for Internet merchants with the ability to create their own online business and participate in e-commerce at a minimal cost. OpenCart is a turn-key ready “out of the box” shopping cart solution. You simply install, select your template, add products and you’re ready to start accepting orders.

 

See more
Front: http://demo.opencart.com/
Admin: http://demo.opencart.com/admin/
Username: demo Password: demo

 

4) VirtueMart
virtuemart-logo

VirtueMart is an Open Source E-Commerce solution to be used together with a Content Management System (CMS) called Joomla!. Joomla! and VirtueMart are written in PHP and can be used in typical PHP/MySQL environments. Viruemart is not developed by Joomla!, however its works perfectly with it and blends seamlessly with Joomla!. If you would like to read more then here is an article which VirtueMart – A Perfect Ecommerce Platform for Joomla!

 

See more
Front: http://virtuemart.net/features/demo
Admin: http://demo.virtuemart.net/administrator/
Username: demo Password: demo

 

5) OSCommerce
oscommerce-logo

OSCommerce is an online shop e-commerce solution that offers a wide range of out-of-the-box features that allows online stores to be setup fairly quickly with ease, and is available for free as an Open Source based solution. Today, osCommerce has been taken to the next level, moving towards an e-commerce framework solution that not only remains easy to setup and maintain, but also making it easier for store administrators to present their stores to their customers with their own unique requirements.

 

See more
Front: http://demo.oscommerce.com/

 

6) Zen-cart
zencart-logo

ZenCart truly is the art of e-commerce; free, user-friendly, open source shopping cart software. The ecommerce web site design program is being developed by a group of like-minded shop owners, programmers, designers, and consultants that think ecommerce web design could be and should be done differently. ZenCart offers great support and tutorials and has extensive documentation to help you at every stage.

 

See more
Front: http://www.15.zen-cart-demo.com/
Admin: http://www.15.zen-cart-demo.com/
Username: admin Password: password123

 

7) UberCart
ubercart-logo

Ubercart is an exciting open source e-commerce shopping cart that fully integrates your online store with Drupal, the leading open source content management system. This is a killer combination for anyone looking to build a community around a product, sell access to premium content, offer paid file downloads, and much much more!

 

See more
Front: http://www.ubercartdemo.com/
Admin: http://www.ubercartdemo.com/user/login
Username:demo Password: demo

 

8) Xcart
x-cart-logo

X-Cart or XCart is a PHP/MySQL based secure shopping cart software that uses Smarty template engine for easy and unlimited design creation. X-Cart is template based software with open source code. This means you can modify the look & feel and functionality of the shopping cart the way you need should you require any business specific features.

 

See more
Front: http://demo.x-cart.com/demo/home.php
Admin: http://demo.x-cart.com/demo/admin/
Email: demo-master@x-cart.com Password: master

 

9) Miva Merchant
miva-merchant-logo

Miva Merchant is a mature and robust e-commerce storefront solution with the usual sorts of e-commerce functionality. It allows you to create and manage an e-commerce catalogue, handle payments and shipping – as well as Inventory and Merchandising capabilities.

 

See more
Front: http://www.mivamerchant.com/products/demo/mm5/merchant.mvc?Screen=SFNT&Store_Code=Miva_fresh_2
Admin: http://www.mivamerchant.com/products/merchant/mm5/admin_demo.html
Username: demo Password: demo

 

10) CubeCart
cubecart-logo

CubeCart is a complete ecommerce shopping cart software solution. With CubeCart you can quickly setup a powerful online store to sell digital or tangible products to new and existing customers globally. CubeCart is one stop shop solution for everyone, whether you are a retailer or a web developer, you can install CubeCart and get your ecommerce store running in minutes.

 

See more
Front: http://demo.cubecart.com/cc5/
Admin: http://demo.cubecart.com/cc5/admin.php
Username: admin Password: password

 

Save