Saturday, September 7, 2013

How to handle select and option tag in jquery?

1. Set and get value to single selection select - We can set value of single selection select using val() function.
Example1 -
<Select id="number">
    <option value="1">One</option>
    <option value="2">Two</option>
    <option value="3">Three</option>
    <option value="4">Four</option>
    <option value="5">Five</option>


        var value = $("#number").val();

In above example in number list selected option is 2(Two). If we pass parameter to val() fucntion. That set value to element. First element set value and second statement get current selected value.

2. Handle multiple selection - In multiple selection list, user can select multiple optin for that need to add (multiple="multiple") attribute. To get all selected value, need to pass optin:selected selector. See folowing example
Example2 -
<Select id="number" multiple="multiple">
    <option value="1">One</option>
    <option value="2" selected="selected">Two</option>
    <option value="3">Three</option>
    <option value="4" selected="selected">Four</option>
    <option value="5">Five</option>

    //Get all selected optin
    var selectedOption = $("#number option:selected);

    //Loop for all selected optin
        $("#number option:selected").each(function() {
        //get option object
        var option = $(this);

        //Get option value
         var value = $(this).val();

        //Get optin text
        var text = $(this).text();
        //Write your code here

In above example we can use optin:selector to get all selected option. In loop we can get optin object, its value and text.

3. Shift all selected optin into ne select list to another - loop all selected optin for first select and push into another.
Example3 -
<Select id="numberList1" multiple="multiple">
    <option value="1">One</option>
    <option value="2" selected="selected">Two</option>
    <option value="3">Three</option>
    <option value="4" selected="selected">Four</option>
    <option value="5">Five</option>

<Select id="numberList2" multiple="multiple">
    <option value="10">Ten</option>
    <option value="12" selected="selected">Twel</option>
    <option value="13">Thirteen</option>
    <option value="14" selected="selected">Fourtheen</option>
    <option value="15">Fifteen</option>

    //Get all selected optin
    var selectedOption = $("#number option:selected);

    //Loop for all selected optin
        $("#numberList1 option:selected").each(function() {
        //Create new option for second list
        $("#numberList2").append($('<option>', {
                    value: $(this).val(),
                    text : $(this).text()

        //Remove first optin from list1

In above example, All selected optins and move into another.

Friday, August 30, 2013

How to configure Symfony2

I have started to develop my web application in symfony in last November, I have faced lots of issues with configuring Symfony framework, Actually it is essay to setup and configure. See the following deals about Symfony. The goal of this blog is to setup and configure the symfony application.

What is Symfony? 
Symfony  is PHP based web application development framework. That having power to scall your big application with security.

Download - Download symfony from

Directory Structure OF Symfony2
Symfony2.3 durectory structure include following six directories,
path/to/webroot/ <- your web server directory (sometimes named htdocs or public)
    Symfony/ <- the new directory

app - App directory contain AppKernel.php . This class is used to register the bundle. For registering the bundle,  just need to create object of bundle class.

Als app directory contain cache, config, logs, and also resourses directory. Cache directory creates a framework readable code as per dev/prod environment. Logs directory contain log file. Symfony framewor logs each event, info, or exception in log file. Config directory contain all application configuration. And Resources directory contain all global resources like base twig or base layout, Some time we can add a common macro.

src - This directory contain the actual development classes. In symfony2.3 download backup contain default "Demo bundle". As per requirement user can define single bundle application or multiple bundle for as per functionality or requirement.

vendor - This directory contain the all necessary library for the project, We can call this as bundles. Symfony basic bundle provides the lots of bundles, like Swift Mailer, Doctrine, Form, Twig etc.

User can also configure custom bundles, Actually that is the power of symfony to use third part bundles as a components.

web- This directory contain all public resources. app.php is the start up file.

After coping Symfony into your web directory, start apache and run following URL


 After running this URL, Sye mfony welcome page will show as the result of your hardwork.

Symfony Welcome Page
First time, We need to configure the PHP extension and configuration. Click on configuration button on welcome screen to check required extension and packages. Configuration page will automatically check s and give you report what is require.

If any missing extension then install that extension first.

If you already setup all extension and dependency then click on  Run the Demo button.

How to add my first page?
The basic componenets for creating your first hello page is,

Controller - Controller is class, in that we can define all action in framework, Any userdefine controller class must be extends from "Symfony\Bundle\FrameworkBundle\Controller\Controller" class.

To create your own controller class, Click on controller directory and create new class named HelloController and extend from Symfony Controller class.

Action - Each action function contain postfix Action. e.g, HelloAction

class HelloController extends Controller { 

    public function helloAction(Request $request) {
         new $this->render('DemoBundle:hello:hello.html.twig', array());;

Route - To execute the logic from web we need to create route.  See following sample route,

    pattern:  /hello
    defaults: { _controller: DemoBundle:Hello:hello }

pattern - Pattern conten the actual URL the will append after app.php or apps_dev.php.
defaults - Its path of action,

Twig -To design view, Symfony used twig as a default template engine, But We can setup smarty also with symfony by changing default template engine. add hello.twig in "Resources->views->hello" directory.

Add Hello message in twig page. Save project and run following url.


Your Hello page will be display.

If you want to learn more about Symfony then go to for more information. Enjoy this steps and run your first Symfony2.3 application.

Total Pageviews