Showing posts from 2014

MongoDB Tutorials : Aggregation Framework

MongoDB Aggregation Framework groups set of documents together and performs certain operation on this grouped documents and returns results in the form of documents. MongoDB aggregation answer to those query which requires grouping of documents.

Aggregation framework works on three type of model Aggregation pipelineMap ReduceSingle Purpose Aggregation Operations

Now let see how MongoDB Aggregation Framework works with simple example.
Suppose you are MongoDB application developer in a respected company and you have been given a MongoDB database that holds information about human population which is distributed according to cities and their states.
here is one sample document.

for this tutorial collection name is zips.
on first day your manager come and asks you to calculate total population of state DC.
your simplest approach to solve…

PHP Tutorials : Autoload PHP Classes

This tutorials post will explain PHP autoloader and namespace concept using few basic question and answer regarding PHP autoload functionality along with some examples.What is Autoloading in PHP?PHP provides helper functions to include or import PHP files, if it has not been included before. if we use PHP autoload then we don't need to write require or include statement for each PHP class files.
Why we need auto loading?It is a good question. why we need it, although we can write require or include statements whenever we need. As PHP has evolved using OOPs concept, we create more classes for our PHP project and create a separate PHP file for each single PHP class. Hence we increase the number of require or include statements. therefore we need some standard way to include each files rather specifying include statement by our self every time. that is why PHP has provided some useful methods to resolve this problem.
PHP Autoloading MethodsPHP uses two function, one is magic metho…

JSON Tutorials : Getting Started

JSON is widely accepted text formatted structured data. JSON stands for "JavaScript Object Notation". In general JSON can represent 1. Object of database record. 2. Object to represent a list of HTML elements. 3. Result of search query. 4. Response of an Ajax call. Here you can see JSON is used in many different areas and for many different scenarios. This means it has simple data structure. most of programming languages adopt it and it can flow easily from one connection to another. You can find JSON office definition here JSON Official Site. JSON is represented by two structural types, which includes two primitive types. Structural types

Array: A sequential list of primitive data types between square brackets [ ]
Object: Collection of key, value pair stored inside curly braces { }, where value would be primitive data type

Primitive types:
There are two primitive types key and value. "key" should be string and "value (data type)" could be anythin…

Doctrine 2 Tutorials: Installation and Configuration

This tutorial post will help you to install Doctrine2 inside your PHP project and configure it so that you can use it's features in plain PHP project.

This post illustrates installation of Doctrine2 using Composer.

Installation First create your project directory

now create composer.json

then add following repository information.

{ "require": { "doctrine/orm": "*" } }
Now you are ready to install it via composer, but first we need to install composer into you machine.

Then initiate following command to install Doctrine2

composer creates "autoload.php" file which helps you to autoload all PHP classes of Doctrine2 ORM project.

Configuration First create configuration file configuration.php for Doctrine2 and include autoload.php inside it.

<?php// configuration.php// Include Composer Autoload require_once"vendor/autol…

Twig Tutorials: Install and Configure

In this tutorial we will see how to install Twig inside your PHP project and then configure it so that we can create use Twig template inside our PHP web application.

later we see a simple Twig template example which will display "Welcome to Twig template" message.

lets see each step one by one.

we can install Twig template via Composer, Git or from PEAR.

in this tutorial post we will install Twig using Composer.

for that we need to create "composer.json" file.

{ "require": { "twig/twig": "1.*" } }
the from console run following command.

  php composer.phar install   

this command will install Twig library.

To use Twig template we need configure it first, for that we will create index.php file which will setup Twig autoloader and generate the Twig environment.

using this Twig environment we will render Twig template

include __DIR__ . "/vendor/twig/twig/lib/Twig/Autoloader.php"; //regist…

Generate SSH Public Key for GitHub and Bitbucket

This post demonstrate how to generate SSH private and public key with simple steps and help you to add public key inside your GitHub and Bitbucket account.
But first why we need this SSH public key?
Whenever you access or do some Git operation on remote repository using HTTPS connection from your local machine, you need to authenticate yourself first using username and password.
It looks simple earlier, but later becomes headache.
SSH connection helps us to authenticate using public and private keys, that we generate only once, later we don’t need to authenticate, SSH will do this behalf of us.
But how does it works?
SSH authenticate you using an identity. And this identity is combination of private, public key.
Private Key resides in your local machine and public key inside your GitHub or Bitbucket account.
When you access Git repository, SSH combines these two keys and authenticates you. To use SSH you need to install it first. I assumed that you have already installed it, if not  then please…

Symfony Tutorials: Event Dispatcher

Symfony EventDispatcher is object which interacts with different set of objects when certain event happens.
To illustrate Event Dispatcher definition let’s consider the online shopping website example.
suppose you want to purchase a mobile from online shopping website , but unfortunately that mobile is out of stock.
Then you subscribe into online shopping website for this mobile availability.
When mobile comes in stock, online shopping website notifies you about mobile phone’s availability via email.
In above scenario

you are the Event Listener / Event Subscribermobile availability is Eventonline shopping website is Event Dispatcher.

Symfony EventDispatcher works in same manner.for example, whenever there is HTTP request, Kernel creates a request object and it dispatches an event kernel.request.
Whoever subscribes to kernel.request event gets notified.
So here you might be having few questions in my mind.
What is Event?Event object describe what event is and add some additional information so …