Here is a beautiful tool for installing Mac System. It’s just a one click installer which guide you step by step to

  • Install Ruby on Rails
  • Git Initialization of RoR Project
  • Cloud Deployment with Engineyard 500 hours of trial version.
  • Small Tutorial to start with RoR.

from Engine Yard on Vimeo.

Reference: http://railsinstaller.org/#osx

Many of us use Zend Framework for their local development in windows machine. Very few of us use Mac OS or Linux. There are lots of installation process available in Web but, very few of us get the proper way to install and configure zend Framework in their windows machine.

Therefore i am writing this post with some simple and easy steps. So lets start.

Requirements before Installation:

  • XAMPP Installation: For example I install xampp is installed in my F:/ Drive
  • Download Zend Framework Version 1.11.11. After Unzipping the folder you will have two(02) folder called “bin” and “library”. Inside the “bin” folder you will find 3 files(zf.bat, zf.sh, zf.php). Inside the library folder you will find the Zend folder which contains the core Zend Library.

Step 01:

Create a virtual host inside our apache virtual host configuration file called httpd-vhosts.conf. You will find the file at: F:\xampp\apache\conf\extra\httpd-vhosts.conf. i have created my own virtual in the following fashion:

<VirtualHost *:80>
    ServerAdmin masudiiuc@gmail.com
    DocumentRoot "F:/xampp/htdocs/zf/"
    ServerName zf.masudiiuc.com
    ##ServerAlias www.dummy-host.localhost
    ##ErrorLog "logs/dummy-host.localhost-error.log"
    ##CustomLog "logs/dummy-host.localhost-access.log" combined
</VirtualHost>

We are going to put our application folder inside the XAMPP root folder htdocs. We will name our project “zf”, therefore we will create a folder “zf” inside the root directory. therefore we placed the DocumentRoot settings to “F:/xampp/htdocs/zf/”.

Step: 02:

The very next thing we have to do is list the host name in windows host folder. Our host file is available at “c:\Windows\System32\drivers\etc\hosts“. At the very bottom of the page add a new line with our host information exactly same as the below line:

127.0.0.1       zf.masudiiuc.com

Step: 03

Now create a folder called “zf” inside the root folder of XAMPP. Now  restarts the XAMPP apache service and browse the http://zf.masudiiuc.com. You will see a blank page with web index listing.

Step: 04

Now we have to configure zend Framework. We know Zend library is a Huge library and we will have to use the library for all application. So its better to place the librarl in such location from where all our apps can share the library rather than using individual Library folder. So we are going to add the library in a common windows PATH and also going to add that in php “include_path” by editing the php.ini file inside F:\xampp\php\php.ini. So lets do it…

  • Copy the library folder from zend framework 1.11.11 folder and paste that to a secure directory like i put it in C:\zf\library/ and put bin folder C:\program files\bin
  • Now we are going to add the “bin” folder location to the windows path variable. we have to add the php.exe location to the windows path variable so that the zf.bat file gets the php.exe file to excute any php code. Our php.exe is located at F:\xampp\php/ location.  To do that goto Control panel—>system–>advanced settings–>Enviromental Variables location. In the System Variables section there will be a PATH variable. we have to edit that one and add the following line:
    ;C:\Program Files\bin;F:\xampp\php

  • Next thing we need to add the Zend Framework Library location to the php.ini file. to do so go to: F:\xampp\php and open the php.ini file. then add the following line.
    include_path = ".;F:\xampp\php\PEAR;C:\library"

  • Now restart your windows.

 

After Restarting windows, open your command line. goto the root directory of XAMPP at: F:\xampp\htdocs\. Now type the following Command

zf show version

This will show the Current Zend Framework version. which also let you know that your current configuration is done successfully.

Now we are going to create our project structure using Zend framework command line tool. Here is the command:

zf create project zf

This will create a project structure inside the zf folder. If you browse the http://zf.masudiiuc.com you will see the project folder. To see the default view of the framework you to modify the virtual host document root a bit more: just change the following line

DocumentRoot "F:\xampp\htdocs\zf\" to DocumentRoot "F:\xampp\htdocs\zf\public\"

This is because zend Executes all controller by going through public/index.php file. this is due to security reason of the application.

So this is simple to configure your zend framework inside your windows folder. So enjoy and put comments.

 

 

I have working with codeigniter for last 3/4 years. i have the opportunity to developed some application using codeigniter. I found some feature common almost in all application. Some parts of the development needs extensive care such as handling the Models. It is very difficult to develop new tool thinking about deadline of project. So its better if we use some community libraries and contribute on those things. it will take less time and increase the productivity as well.

Today i am going to focus on some libraries which i personally use and get much benefits from those things. Here are those libraries:

Authentication Library: DX Auth
Authentication is a basic and most common part of every web applications. Login, Logout, Registration, change password, forgot password etc. We can create such libraries but sometime its so boring to recreate them as i fill sometime. Therefore in the codeigniter forum, there are lots of authentication libraries available. But i personally found Dx_auth very useful. Because this libraries has maximum number of features with a well documentation. Here is some of the core features:

  • Basic auth (Login, logout, register, change password).
  • Remember me.
  • Login using username or email address or both (depend on config settings).
  • Forgot password.
  • Ban user.
  • Last login IP address and time (optional).
  • Email activation (optional).
  • User Profile (optional).
  • Role based (admin, user, moderator, etc). Inheritance also supported (optional)
  • Restrict page based on URI and role (optional).
  • Custom permission for each role (optional).
  • Login attempt (optional). You can use this to display catpcha after specified try to login to prevent bot.
  • Event feature (For example: You can put your own code like PM welcome message after user activated, etc).
  • Captcha (optional, native and reCAPTCHA is available).
  • Simple admin panel (So you can customize it, include it into your own admin panel, or delete if you don’t need it).
  • Most of the feature is optional, means you can turn it off in config file, delete it, or just don’t use it.

Documentation Linkhttp://dexcell.shinsengumiteam.com/dx_auth/

Codeigniter ORM Library: Datamapper ORM
Deal with model is very important in every application. ORM is one of the core features for Data Mapping. Some time we create this mapper by ourself. but as there is a build in Library specially for Codeigniter, why we should build another one. DataMapper ORM is such one which saves lots of our time and give us a clear view of managing models.

Here is some core features of the Library:

  • Everything is an object!
  • Easy to setup, easy to use.
  • Custom Validation on object properties.
  • Lazy Loading (related objects are only loaded upon access).
  • Relations and their integrity are automatically managed for you.
  • One to OneOne to Many, and Many to Many relations fully supported.
  • Select data in the style of Active Record (with or without Method Chaining).

Documentation link: http://datamapper.wanwizard.eu

CodeIgniter and Doctrine
This is another way to mapping database. You will have a complete guideline from the following link:
Documentation Link: http://www.phpandstuff.com/articles/codeigniter-doctrine-from-scratch-day-1-install-and-setup

Here is the list of articles. Please have a look on this as well.

Hope that, this links will work for you and i will come with more updates on such things.

Codeigniter Framework is one of the best PHP Framework around the world. Several people use this for different purpose. Application with Codeigniter is very fast in comparison to other framework. Good documentation, easy structure is main features.

During development some of us don’t know about some already build-in libraries which makes our development easy to easier. Today i will discuss about some of the libraries:

Message Library
one of the important library is this Message library. we need to show different types of message in our application. sometime we need to show success message after redirect to another page. Again we need to show error message on unsuccessful operations, warnings as well. i found this library very much useful in comparison to other existing libraries of codeigniter.

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Message:: a library for giving feedback to the user
 *
 * @author  Adam Jackett
 * @url http://www.darkhousemedia.com/
 * @version 2.1
 */

class CI_Message {

    var $CI;
    var $messages = array();
    var $wrapper = array('', '');

    function CI_Message($config){
        $this->CI =& get_instance();
        $this->CI->load->library('session');

        if($this->CI->session->flashdata('_messages')) $this->messages = $this->CI->session->flashdata('_messages');
        if(isset($config['wrapper'])) $this->wrapper = $config['wrapper'];
    }

    function set($message, $type, $flash=FALSE, $group=FALSE){
        if(!is_array($message)) $message = array($message);
        foreach($message as $msg){
            $obj = new stdClass();
            $obj->message = $msg;
            $obj->type = $type;
            $obj->flash = $flash;
            $obj->group = $group;
            $this->messages[] = $obj;
        }

        $flash_messages = array();
        foreach($this->messages as $msg){
            if($msg->flash) $flash_messages[] = $msg;
        }
        if(count($flash_messages)) $this->CI->session->set_flashdata('_messages', $flash_messages);
    }

    function get($type=FALSE, $group=FALSE){
        $output = array();
        if(count($this->messages)){
            foreach($this->messages as $msg){
                if($type !== FALSE){
                    $output[] = $msg->message;
                } else {
                    if(!isset($output[$msg->type])) $output[$msg->type] = array();
                    $output[$msg->type][] = $msg->message;
                }
            }
        }
        return $output;
    }

    function display($group=FALSE, $wrapper=FALSE){
        if(count($this->messages)){
            $output = $this->get(FALSE, $group);
            echo ($wrapper !== FALSE ? $wrapper[0] : $this->wrapper[0])."rn";
            foreach($output as $type => $messages){
                echo '<div class="message-'.$type.'">'."rn";
                foreach($messages as $msg){
                    echo '<p>'.$msg.'</p>'."rn";
                }
                echo '</div>'."rn";
            }
            echo ($wrapper !== FALSE ? $wrapper[1] : $this->wrapper[1])."rn";
        }
    }

}

How to Use?

1. Put this library to libraries folder
2. load this library to your application manually or using autoload.php.
3. syntax of setting message:

$this->message->set('YOUR_MESSAGE', 'MESSAGE_TYPE', 'REDIRECT_TRUE_OR_FALSE');

if you are about to show a message after redirection, write the following code:

$this->message->set('YOUR_MESSAGE', 'MESSAGE_TYPE', true);
redirect('/');

if you are about to show a message in the same page, write the following code:

$this->message->set('YOUR_MESSAGE', 'MESSAGE_TYPE', false);
$this->load->view('home.php',$data);

To show the message inside a view, just put the following code inside your view:

$this->message->display();

To get a closer look on this library follow the following link

http://codeigniter.com/wiki/Message/

Layout Library
Its very important to maintain layout mechanism in modern web application. To do so, there are lots of libraries. among those, this one is better and easy to implement and understand.

<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

class Layout
{

    var $obj;
    var $layout;

    function Layout($layout = "layout_main")
    {
        $this->obj =& get_instance();
        $this->layout = $layout;
    }

    function setLayout($layout)
    {
      $this->layout = $layout;
    }

    function view($view, $data=null, $return=false)
    {
        $loadedData = array();
        $loadedData['content_for_layout'] = $this->obj->load->view($view,$data,true);

        if($return)
        {
            $output = $this->obj->load->view($this->layout, $loadedData, true);
            return $output;
        }
        else
        {
            $this->obj->load->view($this->layout, $loadedData, false);
        }
    }
}
?>

You can have more details about this library at codeigniter forum link:

http://codeigniter.com/wiki/layout_library/

to be continued…

Please have a look on part one if don’t read the previous one:
Google Contact’s API with Codeigniter Framework [part-01]

In the previous post we are missing a function called “processFeedResult($feed)” at 36. Here is the details:

<pre>/**
 * Parse Feed Result
 *
 * @access	private
 * @param	Zend Gdata Object $feed
 * @return	object			  $results
 */
private function _processFeedResult( $feed ){
	if( $feed ){
		$results = array();
		foreach( $feed as $key => $entry ){
			$xml = simplexml_load_string( $entry->getXML() );

			//create a new Object
			$obj = new stdClass;

			//set value to the object
			$obj->name     = (string) $entry->title;
			$obj->orgName  = (string) $xml->organization->orgName;
	        $obj->orgTitle = (string) $xml->organization->orgTitle;
	        $obj->edit     = (string) $entry->getEditLink()->href; // require for edit/delete

			foreach( $xml->email as $email ){
				$obj->emailAddress[] = (string) $email['address'];
			}
			foreach ($xml->phoneNumber as $p) {
	        	$obj->phoneNumber[] = (string) $p;
	        }
	        foreach ($xml->website as $w) {
	        	$obj->website[] = (string) $w['href'];
	        }

			$results[] = $obj;
		}
		return $results;
	}
	return false;
}

Now are simplifying the process by creating two functions. One will create the connection with a API call and returns the Object. Then we will create another function for adding new contacts to that account.

Step:01
Creating common connection with Google Account

/**
 * Create connection to google Account
 *
 * @access private
 * @param	none
 * @return	object	$gData
 */
private function _connectToAgentE3GoogleAccount( $update=false ){
	$this->load->library('zend');
	$this->zend->load('Zend/Loader');

	Zend_Loader::loadClass('Zend_Gdata');
    Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
    Zend_Loader::loadClass('Zend_Http_Client');
    Zend_Loader::loadClass('Zend_Gdata_Query');
    Zend_Loader::loadClass('Zend_Gdata_Feed');

    try{
    	//perform account login and set protocol version
		$client = Zend_Gdata_ClientLogin::getHttpClient('TEST_EMAIL_ACCOUNT', 'PASSWORD', 'cp');

		if( $update ){
			$client->setHeaders('If-Match: *');
		}

		$gData  = new Zend_Gdata( $client );
		$gData->setMajorProtocolVersion(3);

		return $gData;

	}catch(Exception $e){
		die('Error: ' . $e->getMessage());
	}
}

Step:02
Add new account to Google Account using the connection object.

/**
 * Add New Contacts to E3 Gmail account
 *
 * @access	public
 * @param	string		$emailAddress
 * @param	string		$fullName		[optional]
 * @param	string		$phone			[optional]
 * @param	string		$company_name	[optional]
 * @return	string		$entryId
 */
public function addContactToE3GoogleAccount( $emailAddress, $fullName='', $phone='', $company_name=''){
	// create new entry
	$doc  = new DOMDocument();
    $doc->formatOutput = true;

    $entry = $doc->createElement('atom:entry');
    $entry->setAttributeNS('http://www.w3.org/2000/xmlns/' ,'xmlns:atom', 'http://www.w3.org/2005/Atom');
    $entry->setAttributeNS('http://www.w3.org/2000/xmlns/' ,'xmlns:gd', 'http://schemas.google.com/g/2005');

    $doc->appendChild($entry);

	// add name element
	if( !$fullName ){
		$fullName = 'Unkown Name';// keep the google db not empty field
	}

	$name = $doc->createElement('gd:name');
	$entry->appendChild($name);
	$fullName = $doc->createElement('gd:fullName', $fullName);
	$name->appendChild($fullName);

	if( !$phone ){
		$phone = "000001"; // keep the google db not empty field
	}

	$phoneNumber = $doc->createElement('gd:phoneNumber', $phone);
	$phoneNumber->setAttribute('rel' ,'http://schemas.google.com/g/2005#mobile');
	$entry->appendChild($phoneNumber);

	// add email element
	$email = $doc->createElement('gd:email');
	$email->setAttribute('address', $emailAddress);
	$email->setAttribute('rel' ,'http://schemas.google.com/g/2005#work');
	$entry->appendChild($email);

	// connect to google Account and insert entry
	$contactObj  = $this->_connectToAgentE3GoogleAccount();
	$entryResult = $contactObj->insertEntry($doc->saveXML(), 'http://www.google.com/m8/feeds/contacts/default/full');

	return $entryResult->id;
}

Note:
So far i am able to insert some certain information using the google api’s. Here is some key note:

  • You can insert Email, Name, Phone number only
  • You can’t insert any field as blank during insert. if you enter a field blank you will face problem during updating that field information. So if any information is not available, set a sample text to that field. Ex: $phone = “000001″

Example:
1.suppose we have two server source.com and destination.com
2.we are going to transfer a backup.sql from source.com to destination.com server.
3.we have ssh access(username & Password) to both server.

Step:01
Login to destiantion.com using ssh terminal

root@destination.com#:

step:02
Now create a a folder called back_from_source in destination.com

root@destination.com#:mkdir back_from_source
root@destination.com#:

step:03
we have backup.sql file at source.com in /var/www/sql/backup.sql. we are going to copy the file in destination.com as backup.sql(you can use different name as well). we are using SCP command to do the job.

command syntax:

scp user@hostname.com:file_path/filename destionation_path/filename

example:

root@destination.com#:scp root@source.com:/var/www/sql/backup.sql /home/destionation_folder/backup.sql
root@source.com password:
Copy progress information will be shown with bandwidth
root@destination.com#:

That’s all. Have fun.

Google has vast number of API’s. Among them Google Contacts API is one of them. Recently i have to work with this API including Codeigniter. But there is very limited number of post which describes everything very clearly. Therefore as i worked with this one, i am sharing my knowledge here.

Tools that i used:

  • Framework: Codeigniter
  • Library: Zend Library with Codeigniter
  • A test account in Google for testing the API functionality.

What will be done:

  • Import list of contacts from an Existing Google Account and add them to a another google account(test account)
  • Update Contact information through API
  • Delete Contact from Google Account using API
  • Add new contact to google account

A. Import Contacts from a Google Account

First of all, add the Zend Library folder in codeigniter libraries folder. Create a library file in codeigniter/library folder called Zend.php. Put the following contents into the file:

<?php if (!defined('BASEPATH')) {exit('No direct script access allowed');}

class Zend
{
    /**
     * Include the Zend library once
     * we load the zend Library class
     *
     * @param   none
     * @return  none
     */
    function __construct(){
        ini_set('include_path',
        ini_get('include_path') . PATH_SEPARATOR . APPPATH . 'libraries');

    }

    /**
     * Load Zend Library
     *
     * @param   string $class
     * @return  object $class
     */
    function load($class){
        require_once (string) $class . EXT;
    }
}
/* End of Zend.php */

Then we need a Existing Google Email account User Name and Password. We will pass the parameter through our controller methods. Inside the method we will load the library Zend.php. Then using this library we will load the Zend Gdata Library for importing the Contacts using Google API’s.
Have a look on the following code:

	/**
	 * Import Contacts using Zend Library
	 *
	 * @access	private
	 * @param	string	$accountUserName
	 * @param	string 	$accountPassword
	 * @return	none
	 */
	private function _importContacts($accountUserName, $accountPassword){
		$this->load->library('zend');
		$this->zend->load('Zend/Loader');

		Zend_Loader::loadClass('Zend_Gdata');
	    Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
	    Zend_Loader::loadClass('Zend_Http_Client');
	    Zend_Loader::loadClass('Zend_Gdata_Query');
	    Zend_Loader::loadClass('Zend_Gdata_Feed');

	    try{
	    	//perform account login and set protocol version
			$client = Zend_Gdata_ClientLogin::getHttpClient($accountUserName, $accountPassword, 'cp');
			$gData  = new Zend_Gdata( $client );
			$gData->setMajorProtocolVersion(3);

			//perform query and get result from feed
			$query  = new Zend_Gdata_Query('http://www.google.com/m8/feeds/contacts/default/full');
			$query->startIndex = 0;
			$query->maxResults = 25;
		    $query->setParam('orderby', 'lastmodified');
		    $query->setParam('sortorder', 'descending');
			$feed   = $gData->getFeed($query); 

			$this->data['AccountTitle']  = $feed->title;
			$this->data['currentNumber'] = 25;
			$this->data['TotalResults']  = $feed->totalResults;
			$this->data['contactList']   = $this->_processFeedResult($feed);

		}catch(Exception $e){
			die('Error: ' . $e->getMessage());
		}
	}

Comming soon…

This blog will have regular article on latest Framework, API’s, Web-service etc. You will get series of articles so that you can use them to your application. Again Professional Service on development is available .

Please follow us on Twitter, Facebook for Updates.

About this blog

Google API, Youtube API, Twitter API, Flickr API, Zend Framework, Codeigniter Framework are the target post of this Blog.

Photostream

Who am I?

Codeigniter Framework Expert with more than 6 six years of Experience in LAMP Platform. Part-time freelancer in oDesk. Love to play with new tech tools, keen to learn new Tricks of Web.




The On Demand Global Workforce - oDesk

Codeinterior