Tips for Symfony2.3 framework

Standard

Hi Friend  i am sharing some tips for symfony

1) Download the symfony version from symfony website and use maximum implementation from command prompt or terminal.

i) Like bundle creation

ii) Entity creation

iii) database creation

iv) crud creation

After that  may be you have to change something code  based on your requirement

Like when you create any bundle by default it  create  default controller and view file it will  be run on url through this way

http://mysymfonyproject.localhost/hello/symfony

but you can change  based on you requirement

Routing :

login_login_homepage:
pattern:  /hello/{name}
defaults: { _controller: LoginLoginBundle:Default:index }

Change

login_login_homepage:
pattern:  /login
defaults: { _controller: LoginLoginBundle:Default:index }

Controller :

public function indexAction($name)
{

return $this->render(‘LoginLoginBundle:Default:index.html.twig’, array(‘name’ => $name));

}

Change

public function indexAction(Request $request)
{

return $this->render(‘LoginLoginBundle:Default:index.html.twig’, array(‘name’ => ‘test’));

}

view
Hello {{ name }}!

change

{% extends “TwigBundle::layout.html.twig” %}

{% block body -%}
Hello {{ name }}!
<a href=”{{path(‘login_login_logout’)}}”>Logout</a>

{% endblock %}

Than you can run your proper url

http://mysymfonyproject.localhost/login/

Delete Code

if($request->get(‘delid’)!=””)
{
$delid=$request->get(‘delid’);
$em=$this->getDoctrine()->getEntityManager();
$entity = $em->getRepository(‘AdminManageruserBundle:Register’)->find($delid);
$em->remove($entity);
$em->flush();

}

Advertisements

Register and login code front End in symfony2.3

Standard

Controller code

<?php

/* Auther:Vinod K Maurya
* Dated :19/07/2013
* Symfony: Version 2.3
* Scope : Login page implementation
*
*/

namespace Login\LoginBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Login\LoginBundle\Entity\Users;
use Login\LoginBundle\Modals\Login;
class DefaultController extends Controller
{

public function indexAction(Request $request)
{
$session =$this->getRequest()->getSession();
$session->clear();

if($request->getMethod()==’POST’)
{
$username=$request->get(‘username’);
$password=$request->get(‘password’);
$remember=$request->get(‘remember’);

$em=$this->getDoctrine()->getEntityManager();
$repository=$em->getRepository(‘LoginLoginBundle:Users’);
$user=$repository->findOneBy(array(‘userName’=>$username,’password’=>sha1($password)));
if($user)
{
if($remember==’remember-me’)
{
$login = new Login();
$login->setUsername($username);
$login->setPassword($password);
$session->set(‘login’,$login);

}

return $this->render(‘LoginLoginBundle:Default:index.html.twig’, array(‘name’ => $user->getFirstName()));
}
else
{
return $this->render(‘LoginLoginBundle:Default:index.html.twig’, array(‘name’ => ‘login failed’));
}
}
else
{
if($session->has(‘login’))
{

$login=$session->get(‘login’);
$username=$login->getUsername();
$username=$login->getPassword();
$user=$repository->findOneBy(array(‘userName’=>$username,’password’=>sha1($password)));
if($user)
{
return $this->render(‘LoginLoginBundle:Default:index.html.twig’, array(‘name’ => $user->getFirstName()));
}
}
}

return $this->render(‘LoginLoginBundle:Default:login.html.twig’);

}

public function logoutAction(Request $request)
{
$session =$this->getRequest()->getSession();
$session->clear();
return $this->render(‘LoginLoginBundle:Default:login.html.twig’);

}

/* Auther:Vinod K Maurya
* Dated :19/07/2013
* Symfony: Version 2.3
* Scope : Signup page implementation
*
*/

public function signupAction(Request $request)
{
if($request->getMethod()==’POST’)
{
$username=$request->get(‘username’);
$firstName=$request->get(‘firstname’);
$password=$request->get(‘password’);
$user =new Users();
$user->setFirstName($firstName);
$user->setUserName($username);
$user->setPassword(sha1($password));
$em=$this->getDoctrine()->getEntityManager();
$em->persist($user);
$em->flush();
return $this->render(‘LoginLoginBundle:Default:signup.html.twig’,array(‘msg’=>’successfully added’));

}

return $this->render(‘LoginLoginBundle:Default:signup.html.twig’);
}

}

view code

login.html.twig

{% extends “TwigBundle::layout.html.twig” %}

{% block body -%}

<div>

<form method=”post” action=”{{path(‘login_login_homepage’)}}”>
<h2>Please Sign in </h2>
<div>
<input type=”text” name=”username” placeholder=”Email Address”>
</div>
<div>
<input type=”password” name=”password” placeholder=”Password”><br>
<input type=”checkbox” name=”rememeber” value=”remember-me”>Remember Me
</div>
<button type=”submit”>Signin</button>

<a href=”{{path(‘login_login_signup’)}}”>Signup</a>
</form>

</div>

{% endblock %}

signup.html.twig

{% extends “TwigBundle::layout.html.twig” %}

{% block body -%}
<div>
<form method=”post” action=”{{path(‘login_login_signup’)}}”>
<h2>Sign Up </h2>
<div>
<lavel>Username</level>
<input type=”text” value=”” name=”username”>
</div>
<div>
<lavel>First Name</level>
<input type=”text” name=”firstname” >
</div>

<div>
<lavel>Password</level>
<input type=”password” name=”password” >

</div>

<button type=”submit”>SignUp</button>

</form>

</div>

{% endblock %}

——————————

Routing code

login_login_homepage:
pattern:  /login
defaults: { _controller: LoginLoginBundle:Default:index }

login_login_signup:
pattern:  /signup
defaults: { _controller: LoginLoginBundle:Default:signup }

login_login_logout:
pattern:  /logout
defaults: { _controller: LoginLoginBundle:Default:logout }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Login Logout Code in Symfony2.3

Standard

Login  Controller code

<?php
namespace Admin\AdminBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Admin\AdminBundle\Entity\Admins;
class DefaultController extends Controller
{
public function indexAction(Request $request)
{
$session =$this->getRequest()->getSession();
if($request->getMethod()==’POST’)
{

$username=$request->get(‘username’);
$password=$request->get(‘password’);
if($username==”” && $password==””)
{

return $this->render(‘AdminAdminBundle:Default:index.html.twig’,array(‘Error’=>’Please Enter valid username and password’));
}
$em=$this->getDoctrine()->getEntityManager();
$repository=$em->getRepository(‘AdminAdminBundle:Admins’);
$adminUser=$repository->findOneBy(array(‘userName’=>$username,’password’=>sha1($password)));
$sessionid=$adminUser->getId();
$session->set(‘adminlogin’,$sessionid);
if($sessionid==””)
{
return $this->render(‘AdminAdminBundle:Default:index.html.twig’, array(‘Error’ => ‘login failed’,’sessionid’=>”));
}

else
{
return $this->render(‘AdminAdminBundle:Default:login.html.twig’, array(‘name’ => ‘Welcome to ‘.ucwords($adminUser->getFirstName()).’You have Login Successfully’,’sessionid’=>$sessionid));
}

}
else
{
return $this->render(‘AdminAdminBundle:Default:index.html.twig’);

}
}

public function adminlogoutAction()
{
$session =$this->getRequest()->getSession();
$session->clear();
return $this->render(‘AdminAdminBundle:Default:index.html.twig’);
}

}

 

——————————————————————–

 

View Code

{% extends ‘::base.html.twig’ %}
{% block body -%}

<div align=”center”>
{{ Error | default(“”) }}
<form method=”post” action=”{{path(‘admin_admin_homepage’)}}”>
<h2>Please Sign in </h2>
<div>
<input type=”text” name=”username” placeholder=”Username” data-required=”true”>
</div>
<div>
<input type=”password” name=”password” placeholder=”Password” data-required=”true”>
</div>
<button type=”submit” aling=”left”>Signin</button>

</form>

</div>

{% endblock %}

————————————

Routing Code

 

admin_admin_homepage:
pattern:  /admin/
defaults: { _controller: AdminAdminBundle:Default:index }

admin_admin_adminlogout:
pattern:  /adminlogout/
defaults: { _controller: AdminAdminBundle:Default:adminlogout }

 

————————————————————————————————-

Entity Code

<?php

namespace Admin\AdminBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* Admins
*/
class Admins
{
/**
* @var integer
*/
private $id;

/**
* @var string
*/
private $userName;

/**
* @var string
*/
private $firstName;

/**
* @var string
*/
private $password;

/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}

/**
* Set userName
*
* @param string $userName
* @return Admins
*/
public function setUserName($userName)
{
$this->userName = $userName;

return $this;
}

/**
* Get userName
*
* @return string
*/
public function getUserName()
{
return $this->userName;
}

/**
* Set firstName
*
* @param string $firstName
* @return Admins
*/
public function setFirstName($firstName)
{
$this->firstName = $firstName;

return $this;
}

/**
* Get firstName
*
* @return string
*/
public function getFirstName()
{
return $this->firstName;
}

/**
* Set password
*
* @param string $password
* @return Admins
*/
public function setPassword($password)
{
$this->password = $password;

return $this;
}

/**
* Get password
*
* @return string
*/
public function getPassword()
{
return $this->password;
}
}

 

—————————————————————————

Validation code  suggestion

if($request->getMethod()==’POST’)
{
$categorynameid=$request->get(‘category’);
$subcategoryname=$request->get(‘subcategory’);
if($categorynameid==”0″ && $subcategoryname==””)
{
$msg=”Invalid Entry”;
return $this->render(‘AdminCategoryBundle:Default:addsubcategory.html.twig’,array(‘sessionid’=>$sessionid,’catdata’=>$entitydata,’msg’=>$msg));
}
if($categorynameid==”0″ && $subcategoryname!=””)
{
$msg=”Invalid Entry”;
return $this->render(‘AdminCategoryBundle:Default:addsubcategory.html.twig’,array(‘sessionid’=>$sessionid,’catdata’=>$entitydata,’msg’=>$msg));
}
if($categorynameid==”0″ && $subcategoryname!=””)

{
$msg=”Invalid Entry”;
return $this->render(‘AdminCategoryBundle:Default:addsubcategory.html.twig’,array(‘sessionid’=>$sessionid,’catdata’=>$entitydata,’msg’=>$msg));
}

——————————-

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

development Use full command in symfony2.3

Standard

Create bundle  in symfony

vinod@administrator:/var/www/myproject$ sudo  app/console  generate:bundle

Create bundle  in  entity (Means model)

vinod@administrator:/var/www/myproject$ sudo /usr/local/zend/bin/php app/console gen:doctrine:entity

After Entity you have to run this command for add table

sudo /usr/local/zend/bin/php app/console doctrine:schema:update –force

For dump mysql table

vinod@administrator:/var/www/myproject$ sudo /usr/local/zend/bin/php app/console doctrine:schema:update –dump-sql

Create Crud in symfony

vinod@administrator:/var/www/myproject$ sudo /usr/local/zend/bin/php app/console doctrine:generate:crud

Drop Entity

vinod@administrator:/var/www/myproject$ sudo /usr/local/zend/bin/php app/console doctrine:schema:drop –force

 

 

Grep command

vinod@administrator:/var/www/myproject$ grep -R ‘form_widget(form)’ *

Suggestion When you create structure of symfony 2.3

Some problem  will come when you face just like 404 error

Solution : web/app.php

By default  it is   $kernel = new AppKernel(‘prod’, false);

you have to change   $kernel = new AppKernel(‘prod’, true);

Some time site will running as a blank then you have to check you app/appkarnal.php

new Admin\ManageruserBundle\AdminManageruserBundle(),

,     Remove this  camma

new Admin\CategoryBundle\AdminCategoryBundle(),

Connection suggestion

By default it store in parameter.yml file app/config/parameters.yml

# This file is auto-generated during the composer install
parameters:
database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: null
database_name: mysymfonyproject
database_user: root
database_password: root
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
locale: en
secret: cecfc4312075ff2e240064be7675564490dc2e8c
database_path: null

————————————————————————————————————–

Structure suggestion

Front End and backend

by default index page come from layout

vender/symfony/symfony/src/symfony/bundle/twigBundle/resources/view/layout.html.twig

you can use this for  front end

Code :

<!DOCTYPE html>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset={{ _charset }}”/>
<meta name=”robots” content=”noindex,nofollow” />
<title>{% block title %} Symfony Test website

{% endblock %}</title>
<link href=”{{ asset(‘bundles/framework/css/structure.css’) }}” rel=”stylesheet” type=”text/css” media=”all” />
<link href=”{{ asset(‘bundles/framework/css/body.css’) }}” rel=”stylesheet” type=”text/css” media=”all” />

<link rel=”stylesheet” href=”{{ asset(‘bundles/framework/css/css.css’) }}” type=”text/css” />
<link rel=”stylesheet” href=”{{ asset(‘bundles/framework/css/css1.css’) }}” type=”text/css” />
<link rel=”stylesheet” href=”{{ asset(‘bundles/framework/css/css2.css’) }}” type=”text/css” />
<link rel=”stylesheet” href=”{{ asset(‘bundles/framework/css/css3.css’) }}” type=”text/css” />
<link rel=”stylesheet” href=”{{ asset(‘bundles/framework/css/css4.css’) }}” type=”text/css” />
<link rel=”stylesheet” href=”{{ asset(‘bundles/framework/css/css5.css’) }}” type=”text/css” />
<link rel=”stylesheet” href=”{{ asset(‘bundles/framework/css/css6.css’) }}” type=”text/css” />
<link rel=”stylesheet” href=”{{ asset(‘bundles/framework/css/css7.css’) }}” type=”text/css” />
<link rel=”stylesheet” href=”{{ asset(‘bundles/framework/css/css8.css’) }}” type=”text/css” />
<link rel=”stylesheet” href=”{{ asset(‘bundles/framework/css/css9.css’) }}” type=”text/css” />
<link rel=”stylesheet” href=”{{ asset(‘bundles/framework/css/css10.css’) }}” type=”text/css” />
<link rel=”stylesheet” href=”{{ asset(‘bundles/framework/css/css11.css’) }}” type=”text/css” />
<link rel=”stylesheet” href=”{{ asset(‘bundles/framework/css/main.css’) }}” type=”text/css” />

<script language=”javascript” type=”text/javascript” src=”{{ asset(‘bundles/framework/js/js.js’) }}”></script>
<script language=”javascript” type=”text/javascript” src=”{{ asset(‘bundles/framework/js/js1.js’) }}”></script>
<script language=”javascript” type=”text/javascript” src=”{{ asset(‘bundles/framework/js/js2.js’) }}”></script>
<script language=”javascript” type=”text/javascript” src=”{{ asset(‘bundles/framework/js/js3.js’) }}”></script>
<script language=”javascript” type=”text/javascript” src=”{{ asset(‘bundles/framework/js/js4.js’) }}”></script>
<script language=”javascript” type=”text/javascript” src=”{{ asset(‘bundles/framework/js/js5.js’) }}”></script>
<script language=”javascript” type=”text/javascript” src=”{{ asset(‘bundles/framework/js/js6.js’) }}”></script>
<script language=”javascript” type=”text/javascript” src=”{{ asset(‘bundles/framework/js/js7.js’) }}”></script>
<script language=”javascript” type=”text/javascript” src=”{{ asset(‘bundles/framework/js/js8.js’) }}”></script>

<script language=”javascript” type=”text/javascript” src=”{{ asset(‘bundles/framework/js/jquery-1.5.2.min.js’) }}”></script>
<script language=”javascript” type=”text/javascript” src=”{{ asset(‘bundles/framework/js/main.js’) }}”></script>

{% block head %}{% endblock %}
</head>
<body>
<div id=”content”>
<div>
<div>

<img src=”data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAALYAAAA+CAMAAACxzRGDAAAAUVBMVEX////Ly8yko6WLioxkYmVXVVkwLjLl5eWxsLJKSEzy8vJxcHLY2Ni+vb89Oz9XVVh+fH+Yl5n///+xsbLY2Nlxb3KkpKWXlph+fX+LiYy+vr/IZP61AAAAAXRSTlMAQObYZgAABRBJREFUeNrVmtuWoyAQRS1FEEQSzQU7//+hYxUiXsKQZLJWM+chsUloN+WhCuguYoKyYqzmvGasKqH4HyRKxndipcgcumH8qViTM7TkUclcwaHmf5XM0eWq4km1KjdqXfMXJHVe1J3hL8lk5fCGv6wmT+o0d87U+XNrk0Y9nfv+7LM6ZJH5ZBL6LAbSxQ3Q5FDr22Skr8PQSy4n7isnsQxSX4r6pobhjCHHeDNOKrO3yGmCvZOjV9jmt8ulTdXFKdbKLNh+kOMvBzuVRa4Y7MUsdEUSWQe7xxCfZmcwjHU83LqzFvSbJQOXQvptbPnEFoyZtUUGwTeKuLuTHyT1kaP0P6cR01OKvv448gtl61dqZfmJezQmU/t+1R2fJLtBwXV6uWGwB9SZPrn0fKO2WAvQN1PUhHjTom3xgXYTkvlSKHs19OhslETq6X3HrXbjt8XbGj9b4Gi+lUAnL6XxQj8Pyk9N4Bt1xUrsLVN/3isYMug8rODMdbgOvoHs8uAb2fcANIAzkKCLYy+AXRpSU8sr1r4P67xhLgPp7vM32zlqt7Bhq2fI1Hwp+VgANxok59SsGV3oqdUL0YVDMRY7Yg8QLbVUU4NZNoOq5hJHuxEM28Sh/IyUZ8D3reR+yc58EGvOy2U0HQL6G9V+kWyEWHmzaMx6t4o9RhOm/riUiYrzqij4Ptqkn7AaCXqc+F47m04ahfde7YIz8RHEBN6BdVwdIGRVdNbKqYu1Hc0x0wBY4wqC8+XUgBGnj81SZsQB+0yAS1x/BlI/6ebHHk0lauQLuPDpu6EwAVJ7T0rl2uXa23jcqNyOZekhqYHRz3JOANrF4wCCmEs1f9D1lUe0n4NAATed80Y5e0Q7CO2TezM/BR6wKdgQzKbCF4uOQC3Bk0fKAzbFlyRWg3gksA/gmm7eOjrpaKX7fHlEW2xLbE6GZsPiCiShVzN7RG2xTz2G+OJtEqzdJ7APxy3MrSsV0VukXbKMp9lhs5BN6dr3CN+sySUaoxGwfRUM3I/gdPYONgVU+PLX4vUWm32AvUySarbONvcpV2RQEPKKjEBHFk01kQDGRblnn8ZuE9g+JUl8OWAPbkFK2K6JxhJVvF47FzYYnAN22ttwxKYCoH36rheEB7KG/HF/YUaa2G5JF+55tpyrl7B1WHM39HuP2N2EXPl1UBu8vbj4OjvD+NoTE4ssF+ScARgaJY1N7+u8bY/Y9BSM5PKwJbvMVab32YP5FB5TtcYVrGoASolVLTzI7kVsYVxRtAb5n2JXq1vCdtd47XtYItynrN0835PasLg0y13aOPbmPI+on2Lr9e5tjSHvgkAvclUjL3Fsdaw03IzgTR62yYClk7QMah4IQ0qSsoYYbOix6zJR1ZGDNMOY3Bb6W5S6jiyovep3t7bUPyoq7OkjYumrfESp8zSBc/OLosVf+nTnnKjsqR16++WDwpI8FxJWRFTlI6NKnqYJaL96TqjAbo9Toi5QiWBDcmfdFV+T8dkvFe5bItgstbM2X6QG2mVun+cazfRwOS0eiaeRRJKgLfc3BQAqfnhJyz8lfR6580SF/FXVu83Nz1xrrnFqqXL6Qxl47DNSm4RFflvN5sABDD8peouqLLKQXVdGbnqf+qIpOxON4ZyYdJEJ6sy4zS2c5eRPTT4Jyp46qDE5/ptAWqJOQ9e6yE82FXBbZCk1/tXVoshVoopE3CB0zmraI3nbqCJ/gW3ZMgtbC5nh/QHlOoOZBxQCRgAAAABJRU5ErkJggg==” alt=”Symfony” />
</div>

<div>
<form method=”get” action=”http://symfony.com/search&#8221; target=”_blank”>
<div>
<label for=”search-id”>
<img src=”data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAABUElEQVQoz2NgAIJ29iBdD0d7X2cPb+tY2f9MDMjgP2O2hKu7vS8CBlisZUNSMJ3fxRMkXO61wm2ue6I3iB1q8Z8ZriDZFCS03fm/wX+1/xp/TBo8QPxeqf+MUAW+QIFKj/+q/wX/c/3n/i/6Qd/bx943z/Q/K1SBI1D9fKv/AhCn/Wf5L5EHdFGKw39OqAIXoPpOMziX4T9/DFBBnuN/HqhAEtCKCNf/XDA/rZRyAmrpsvrPDVUw3wrkqCiLaewg6TohX1d7X0ffs5r/OaAKfinmgt3t4ulr4+Xg4ANip3j+l/zPArNT4LNOD0pAgWCSOUIBy3+h/+pXbBa5tni0eMx23+/mB1YSYnENroT5Pw/QSOX/mkCo+l/jgo0v2KJA643s8PgAmsMBDCbu/5xALHPB2husxN9uCzsDOgAq5kAoaZVnYMCh5Ky1r88Eh/+iABM8jUk7ClYIAAAAAElFTkSuQmCC” alt=”Search on Symfony website” />
</label>

<input name=”q” id=”search-id” type=”search” placeholder=”Search on Symfony website” />

<button type=”submit”>
<span>
<span>
<span>OK</span>
</span>
</span>
</button><a href=”/login”><span>Login</span></a>
</div>
</form>
</div>
</div>

<div id=”ja-mainnav”>
<div>
<div>
<ul><li><a href=”/welcome” id=”menu1″ title=”Home”><span class=””>Home</span></a></li>
<li><a href=”/register” id=”menu37″ title=”Weekly Horoscope”><span class=””>Register User</span></a>
<li><a href=”/technology” id=”menu37″ title=”Weekly Horoscope”><span class=””>Technology</span></a>
<li><a href=”/industry” id=”menu37″ title=”Weekly Horoscope”><span class=””>Industries</span></a>
<li><a href=”/offering” id=”menu37″ title=”Weekly Horoscope”><span class=””>Offering</span></a>
<li><a href=”/aboutus” id=”menu37″ title=”Weekly Horoscope”><span class=””>About</span></a>
<li><a href=”/contactus” id=”menu37″ title=”Weekly Horoscope”><span class=””>Contact</span></a>
<li><a href=”/blog” id=”menu37″ title=”Weekly Horoscope”><span class=””>Blog</span></a>
<li><a href=”/career” id=”menu37″ title=”Weekly Horoscope”><span class=””>Careers</span></a>
<li><a href=”/news” id=”menu37″ title=”Weekly Horoscope”><span class=””>News</span></a>
<li><a href=”/admin” id=”menu37″ title=”Weekly Horoscope”><span class=””>Admin Login</span></a>
<li><a href=”/send” id=”menu37″ title=”Weekly Horoscope”><span class=””>mail</span></a>

<script type=”text/javascript”>
var megamenu = new jaMegaMenuMoo (‘ja-mainnav’, {
‘bgopacity’: 0,
‘delayHide’: 1000,
‘slide’: 1,
‘fading’: 1,
‘direction’:’down’,
‘action’:’mouseover’,
‘tips’: false,
‘duration’: 300,
‘hidestyle’: ‘fastwhenshow’
});
</script>
</div>
</div>

<div  style=”margin-left:5px;”>
<ul id=”my_slider”>
<li><img  src=”{{ asset(‘bundles/framework/images/mobility.jpg’) }}”></li>
<li><img  src=”{{ asset(‘bundles/framework/images/bussiness_intelligence.jpg’) }}”></li>
<li> <img  src=”{{ asset(‘bundles/framework/images/financial_services.jpg’) }}”></li>

</ul>

</div>

<div>
{% block body %}

{% endblock %}
</div>

<div>

<p style=”text-align: center;”><span style=”text-align: center;”>Home|News|Career|Trademark|Resources|Clients &amp; Alliances|Testimonial|Contact Us|Sitemap|Blog</span><br></p>

<p style=”text-align: center;”>
<span style=”text-align: center;”>Copyright &copy; 2012-2013  <a href=”http://www.symfony.com”>Symfony India</a>, Offshore Software Development – Software Outsourcing Company. All rights reserved</span>
</div>
</div>

</div>
</body>
</html>

When you want to call in your bundle then you have to call like this

{% extends “TwigBundle::layout.html.twig” %}
{% block body -%}
<div>
<p>

Application Services

Every organization’s technology ecosystem has to completely align itself with the business roadmap. To ensure this, an organization needs new software applications, maintenance and modernization of existing applications and seamless integration of the application portfolio.

How Symfony Technology can help

Symfony Technology with its strong team of domain and technical experts can provide best in class application services across various domains. Our experienced team of solution experts design solutions that are secure, flexible and scalable and can serve the needs of a growing business. Our full range of services spanning from application development, application value management, application modernization to enterprise integration services helps you align your Information Technology with your organization’s business roadmap.

We ensure that all our offerings are benchmarked with the industry best practices. We help you to drive innovations and expand into new horizons while keeping overall costs in check.

</p>

<ol>
Service Offerings

<li>Application Development – Symfony Technology leverages upon its decade long technical expertise to deliver software solutions to our customers which fulfil their business needs and bring high ROI to them.</li>
<li>Application Value Management – Symfony Technology provides quality application maintenance & support services to our clients worldwide. Having expertise in providing end to end support including source code changes, enhancements and version control, we follow industry standard practices for vendor transition to ensure no business loss or degradation of customer services.</li>
<li>Application Modernization – Symfony Technology has added value to customers’ application portfolio by migrating obsolete applications to latest technological platforms. We have migrated systems based on traditional platforms such as COBOL, PL/1, FORTRAN and AS/400 and conventional databases like DB2 and IMS.</li>
<li>Enterprise Application Integration (EAI) – Symfony Technology has assisted enterprises worldwide, to integrate their stand-alone applications with the enterprise ecosystem or in integrating their applications with partners’ applications to bring efficiency, speed and transparency.</li>
<li>Package Application Services – Symfony Technology has implemented several widely used standard software packages such as Oracle, SAP, Siebel, etc. in several organizations. We have the domain and technical expertise to perform the required implementation efficiently faster and at a lower cost.</li>
<li>SOA (Service Oriented Architecture) Services – Symfony Technology’s SOA offering allows enterprises to plug in new services and upgrade existing ones to address new business requirements, provides options to make services consumable across different channels and exposes the existing legacy applications as services thus safeguarding IT infrastructure investment.</li>
</ol>

</div>

{% endblock %}

For back end

App/resources/base.html.twig

Code

<!DOCTYPE html>
<html>
<head>
<meta charset=”UTF-8″ />
<title>{% block title %}Welcome!{% endblock %}</title>

{% block stylesheets %}
<link href=”{{ asset(‘bundles/framework/css/structure.css’) }}” rel=”stylesheet” type=”text/css” media=”all” />
<link href=”{{ asset(‘bundles/framework/css/body.css’) }}” rel=”stylesheet” type=”text/css” media=”all” />

{% endblock %}

{% block javascript %}

<script language=”javascript” type=”text/javascript” src=”{{ asset(‘bundles/framework/js/jquery.validate.js’) }}”></script>
<script language=”javascript” type=”text/javascript” src=”{{ asset(‘bundles/framework/js/jquery.validate.js’) }}”></script>

{% endblock %}

<link rel=”icon” type=”image/x-icon” href=”{{ asset(‘favicon.ico’) }}” />

</head>
<body>

<table width=”100%” cellspacing=”0″ cellpadding=”0″>
<tr>
<td  colspan=”2″style=”border-style:solid; border-color:#000 #000;” >

Admin Panel

</td>
</tr>
{{ sessionid | default(“”) }}
{% if sessionid is defined %}

<tr>
<td width=”15%” style=”border-style:solid; border-color:#000 #000;”>
<ul><a href=”/admin/manageruser”><b>User Management</b></a>
<li><a href=”/admin/adduser”>Add User</a></li>
</ul>

<ul><a href=”/admin/category”><b>Cat Management</b></a>
<li><a href=”/admin/category/addcategory”>Addcategory</a></li>
<li><a href=”/admin/category/addsubcategory”>Addsubategory</a></li>
<li><a href=”/admin/category/addchildsubcategory”>Addchildsubcategory</a></li>
</ul>

<ul>Admin Management
<li><a href=”/admin/manageadmin”>Admin<a/></li>
</ul>

<ul><a href=””>User Management</a>

</ul>

<ul><a href=””>gallery Management</a>

</ul>

<ul><a href=””>State Management</a>

</ul>

<ul><a href=””>Country Management </a>

</ul>

<ul><a href=””>Content Management</a>

</ul>

<ul><a  href=”{{path(‘admin_admin_adminlogout’)}}” style=”text-align:right”>Logout</a></ul>
</td>

{% endif %}

<td width=”75%” valign=”top” style=”border-style:solid; border-color:#000 #000;”>

{% block body %}

$session =$this->getRequest()->getSession();

{% endblock %}
</td>
</tr>

<tr>
<td colspan=”2″>
{% block footer %}
<div style=”border-style:solid; border-color:#000 #000;” >
C Panel
</div>
{% endblock %}
</td>
</tr>
</table>

{% block javascripts %}{% endblock %}
</body>
</html>

In you admin bundle you can use like this

{% extends ‘::base.html.twig’ %}
{% block body -%}

<div align=”center”>
{{ Error | default(“”) }}
<form method=”post” action=”{{path(‘admin_admin_homepage’)}}”>
<h2>Please Sign in </h2>
<div>
<input type=”text” name=”username” placeholder=”Username” data-required=”true”>
</div>
<div>
<input type=”password” name=”password” placeholder=”Password” data-required=”true”>
</div>
<button type=”submit” aling=”left”>Signin</button>

</form>

</div>

{% endblock %}

ajax and other usefull code in symfony2.3

Standard

Example a category page  subcategory and child sub category

Controller code

 

public function addsubcategoryajaxAction(Request $request)
{

$session=$this->getRequest()->getSession();
$sessionid=$session->get(‘sessionid’);

$categorynameid=$request->get(‘id’);
$em=$this->getDoctrine()->getEntityManager();
$ctryQuery=$em->createQueryBuilder()
->select(‘c’)
->from(‘AdminCategoryBundle:Category’,’c’)
->where(‘c.parentId=’.$categorynameid);
$ctrFinalQuery=$ctryQuery->getQuery();
$entitydata=$ctrFinalQuery->getArrayResult();
$val=”<select name=’subcateory’>
<option value=’0′>select </option>”;
foreach($entitydata as $valdata)
{
$id=$valdata[‘id’];
$categoryname=$valdata[‘categoryname’];
$val.=”<option value=$id>$categoryname</option>”;
}
$val.=”</select>”;
echo $val;
die;
}

Routing code :

 
admin_category_addsubcategoryajax:
pattern:  /admin/category/addsubcategoryajax/
defaults: { _controller: AdminCategoryBundle:Default:addsubcategoryajax }

 

view  twig code :

{% extends ‘::base.html.twig’ %}

{% block javascript %}

<script language=”javascript” type=”text/javascript” src=”{{ asset(‘bundles/framework/js/jquery-1.10.1.min.js’) }}”></script>
<script lanaguage=”javascript”>
function caregoryVal(id)
{

var dataString = ‘id=’+ id;
$.ajax({type:”POST”, url: “{{ path(‘admin_category_addsubcategoryajax’) }}”,
data:dataString, success: function(response) {
var txt=response;
document.getElementById(“subcat”).innerHTML=txt;
}});

}
</script>

{% endblock %}

{% block body -%}
<div>
<table width=”100%” valign=”top” cellspacing=”0″>
<tr>
<td>

<h1>Add child  Sub Category<h1>
</td>
</tr>
<tr>
<td width=”30%”>
Category Name
</td>
<td>
<select name=”category” onchange=”caregoryVal(this.value);”>
<option value=”0″>
select
</option>
{% for catdataVal in catdata %}
<option value=”{{ catdataVal.id}}”>{{ catdataVal.categoryname}}</option>

{%endfor%}

</select>
</td>
</tr>
<tr>
<td>
Sub Category
</td>
<td>
<div id=’subcat’>
<select name=”subcat”>
<option value=”0″>Subcategory</option>
{% for subcatvalue in subcatval  %}
<option value=””>{{subcatvalue.categoryname}}</option>
{%endfor%}
</select>
</div>

</td>
</tr>

</table>

{% endblock %}

————————————————————————————————————————————

Fetch Query code  based on where condition

$em=$this->getDoctrine()->getEntityManager();
$ctryQuery=$em->createQueryBuilder()
->select(‘c’)
->from(‘AdminCategoryBundle:Category’,’c’)
->where(‘c.parentId!=0’);
$ctrFinalQuery=$ctryQuery->getQuery();
$entitydatasubCat=$ctrFinalQuery->getArrayResult();

return $this->render(‘AdminCategoryBundle:Default:addchildsubcategory.html.twig’,array(‘sessionid’=>$sessionid,’catdata’=>$entitydataCat,’subcatval’=>$entitydatasubCat));

fetch code of all record  of table

$em=$this->getDoctrine()->getEntityManager();
$ctryQuery=$em->createQueryBuilder()
->select(‘c’)
->from(‘AdminCategoryBundle:Category’,’c’)
->where(‘c.parentId=0’);
$ctrFinalQuery=$ctryQuery->getQuery();
$entitydataCat=$ctrFinalQuery->getArrayResult();

 

———————————————————————————————————————-

insert code  in symfony

$caregoryVal=new Category();
$caregoryVal->setCategoryname($categoryname);
$caregoryVal->setParentId(‘0’);
$caregoryVal->setStatus(0);
$em=$this->getDoctrine()->getEntityManager();
$em->persist($caregoryVal);
$em->flush();
$msg=”Added successfully”;

Session management in symforny

$session=$this->getRequest()->getSession();

$sessionid=$session->get(‘sessionid’);

Login logout code —————————————————————————————————————————

namespace Admin\AdminBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Admin\AdminBundle\Entity\Admins;
class DefaultController extends Controller
{
public function indexAction(Request $request)
{
$session =$this->getRequest()->getSession();
if($request->getMethod()==’POST’)
{

$username=$request->get(‘username’);
$password=$request->get(‘password’);
if($username==”” && $password==””)
{

return $this->render(‘AdminAdminBundle:Default:index.html.twig’,array(‘Error’=>’Please Enter valid username and password’));
}
$em=$this->getDoctrine()->getEntityManager();
$repository=$em->getRepository(‘AdminAdminBundle:Admins’);
$adminUser=$repository->findOneBy(array(‘userName’=>$username,’password’=>sha1($password)));
$sessionid=$adminUser->getId();
$session->set(‘adminlogin’,$sessionid);
if($sessionid==””)
{
return $this->render(‘AdminAdminBundle:Default:index.html.twig’, array(‘Error’ => ‘login failed’,’sessionid’=>”));
}

else
{
return $this->render(‘AdminAdminBundle:Default:login.html.twig’, array(‘name’ => ‘Welcome to ‘.ucwords($adminUser->getFirstName()).’You have Login Successfully’,’sessionid’=>$sessionid));
}

}
else
{
return $this->render(‘AdminAdminBundle:Default:index.html.twig’);

}
}

 

Logout code

public function adminlogoutAction()
{
$session =$this->getRequest()->getSession();
$session->clear();
return $this->render(‘AdminAdminBundle:Default:index.html.twig’);
}

 

 

 

————————————————————————————

count record from table function

public function getCategory()
{
$em=$this->getDoctrine()->getEntityManager();
$ctryQueryVal=$em->createQueryBuilder()
->select(‘count(Category.id)’)
->from(‘AdminCategoryBundle:Category’,’Category’);
$finalquery=$ctryQueryVal->getQuery();
$total=$finalquery->getSingleScalarResult();
return $total;

}

 

Paging controller code

namespace Admin\CategoryBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Admin\CategoryBundle\Entity\Category;

class DefaultController extends Controller
{
public function indexAction(Request $request)
{
$session=$this->getRequest()->getSession();
$sessionid=$session->get(‘sessionid’);

/*********update the record ***************/
if($request->get(‘activeid’)!=””)
{
$activeid=$request->get(‘activeid’);
$status=$request->get(‘status’);
if($status == 0)
{
$em=$this->getDoctrine()->getEntityManager();
$ctryQuery=$em->createQueryBuilder()
->update(‘AdminCategoryBundle:Category’, ‘u’)
->set(‘u.status’, 1)
->where(‘u.id=’.$activeid);
}
else
{
$em=$this->getDoctrine()->getEntityManager();
$ctryQuery=$em->createQueryBuilder()
->update(‘AdminCategoryBundle:Category’, ‘u’)
->set(‘u.status’, 0)
->where(‘u.id=’.$activeid);

}

$finalquery=$ctryQuery->getQuery();
$finalquery->execute();
}

$page=$request->get(‘page’);
$count_per_page=4;
$gettotalcount =$this->getCategory();
$totalpage=ceil($gettotalcount/$count_per_page);

if(!is_numeric($page))
{
$page=1;
}
else
{
$page=floor($page);
}
if($gettotalcount<=$count_per_page)
{
$page=1;
}
if(($page * $count_per_page)>$gettotalcount){
$page=$totalpage;
}

$offset=0;
if($page>1)
{
$offset=$count_per_page * ($page-1);
}
$em=$this->getDoctrine()->getEntityManager();
$ctryQuery=$em->createQueryBuilder()
->select(‘c’)
->from(‘AdminCategoryBundle:Category’,’c’)
->where(‘c.parentId=0’)
->setFirstResult($offset)
->setMaxResults($count_per_page);
$ctrFinalQuery=$ctryQuery->getQuery();
$catquery=$ctrFinalQuery->getArrayResult();

return $this->render(‘AdminCategoryBundle:Default:index.html.twig’,array(‘sessionid’=>$sessionid,’catlist’=>$catquery,’totalpage’=>$totalpage,’currentpage’=>$page));
}

—————————————————————

paging view code

<tr>
{%if totalpage >0 %}
<td colspan=”5″>
<table align=”center”>
<tr>

{% for i in 1.. totalpage%}
{%if loop.first %}
<td><a href=”{{path(‘admin_category_homepage’,{ ‘page’: currentpage-1 })}}”>Previous</a></td>
{%endif%}
<td {%if currentpage==loop.index%}>
<a href=”{{path(‘admin_category_homepage’,{ ‘page’: loop.index })}}”>{{loop.index}}</a></td>

{%if loop.last%}
<td><a href=”{{path(‘admin_category_homepage’,{ ‘page’: currentpage+1 })}}”>Next</a></td>
{%endif%}
{%endfor%}

</tr>
</table>
</td>
{%endif%}
</tr>

——————————————————————

 

How to manage path on link

<td>
{% if  catdata.status  == 1 %}
<a href=”{{ path(‘admin_category_homepage’, { ‘activeid’: catdata.id,’status’: catdata.status }) }}”>Active</a>
{% endif %}
{% if  catdata.status  == 0 %}
<a href=”{{ path(‘admin_category_homepage’, { ‘activeid’: catdata.id,’status’: catdata.status }) }}”>Inactive</a>
{% endif %}

</td>

 

How to manage path in form

<form method=”post” action=”{{path(‘admin_admin_homepage’)}}”>

How to manage error if variable not exist

{{ Error | default(“”) }}

Update code in symfony

if($request->get(‘activeid’)!=””)
{
$activeid=$request->get(‘activeid’);
$status=$request->get(‘status’);
if($status == 0)
{
$em=$this->getDoctrine()->getEntityManager();
$ctryQuery=$em->createQueryBuilder()
->update(‘AdminCategoryBundle:Category’, ‘u’)
->set(‘u.status’, 1)
->where(‘u.id=’.$activeid);
}
else
{
$em=$this->getDoctrine()->getEntityManager();
$ctryQuery=$em->createQueryBuilder()
->update(‘AdminCategoryBundle:Category’, ‘u’)
->set(‘u.status’, 0)
->where(‘u.id=’.$activeid);

}

$finalquery=$ctryQuery->getQuery();
$finalquery->execute();
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Symfony framework 2.3 Knowledge

Standard

Hi  I am sharing step by step knowledge of symfony framework.

1) Download symfony from following link    http://symfony.com/download

2) unzip and paste in you local server /var/www

3) Create virtual directory through command

$ /etc/apache2/sites-enabled$ sudo gedit 000-default

<VirtualHost *:80>
ServerName mysymfonyproject.localhost
DocumentRoot /var/www/myproject/web
DirectoryIndex app.php
ErrorLog /var/log/apache2/jobeet-error.log
CustomLog /var/log/apache2/jobeet-access.log combined
<Directory “/var/www/myproject/web”>
AllowOverride All
Allow from All
</Directory>
</VirtualHost>

4 create hosting

/etc$ sudo gedit hosts

mysymfonyproject.localhost

5 )now you can run on you browser through

http://mysymfonyproject.localhost/app_dev.php

6)  click the configure link and generate the database yml file and then copy and manually paste in your app/config/paramereter.yml file

# This file is auto-generated during the composer install
parameters:
database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: null
database_name: mysymfonyproject
database_user: root
database_password: root
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
locale: en
secret: cecfc4312075ff2e240064be7675564490dc2e8c
database_path: null

7) One of the most imparrtent point in symfony framework

you have to change a setting because you will face 404 error on you local server

web/app.php                        $kernel = new AppKernel(‘prod’, false);

you have to chnage this

$kernel = new AppKernel(‘prod’, true);

8) now you can run properly your site

9)  Create and simple bundle on your command  prompt or terminal

ie. open you terminal

i)  var/www/symfony/ sudo app/console generate:bundle

2)  Bundle namespace: Send/SendmailBundle

3) Bundle name [SendSendmailBundle]: SendSendmailBundle

4) Target directory [/var/www/myproject/src]:

5) Configuration format (yml, xml, php, or annotation): yml

6) Do you want to generate the whole directory structure [no]?

Now Send bundle has created successfully

7 Now you have to create entity means table structure

vinod@administrator:/var/www/myproject$ sudo /usr/local/zend/bin/php app/console gen:doctrine:entity

8) The Entity shortcut name: SendSendmailBundle:Email

Here  this is bundle name           “SendSendmailBundle   and    Email is table name

9) Configuration format (yml, xml, php, or annotation) [annotation]: yml

10) by defauly available

vailable types: array, simple_array, json_array, object,
boolean, integer, smallint, bigint, string, text, datetime, datetimetz,
date, time, decimal, float, blob, guid.

11) New field name (press <return> to stop adding fields): name
Field type [string]: 255
Field type [string]: string
Field length [255]: 255

New field name (press <return> to stop adding fields): email
Field type [string]: string

Field length [255]: 255

New field name (press <return> to stop adding fields): yourquestion
Field type [string]: text

now when you run on browser then normally

12)

http://mysymfonyproject.localhost/hello/vinod  is running successfully

but you have to change the  router setting

Send/sendmailBundle/Resource/config/routing.yml

bydefault this way but you have to change

send_sendmail_homepage:
pattern:  /hello/{name}
defaults: { _controller: SendSendmailBundle:Default:index }

———————————————————————————-

send_sendmail_homepage:
pattern:  /send/
defaults: { _controller: SendSendmailBundle:Default:index }

13) Go on controller/defaultcontroller .php and change it.

namespace Send\SendmailBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DefaultController extends Controller
{
public function indexAction()
{
return $this->render(‘SendSendmailBundle:Default:index.html.twig’);
}
}

14)  now you have to update view file Resource/view/Default/index.html.twig

{% extends “TwigBundle::layout.html.twig” %}

{% block body -%}
Hello
{% endblock %}

Now you can run

http://mysymfonyproject.localhost/send/

15) On of the most imprtent command to create table after generate entity

vinod@administrator:/var/www/myproject$ sudo /usr/local/zend/bin/php app/console doctrine:schema:update –force
Updating database schema…
Database schema updated successfully! “1″ queries were executed

Most importent files in symfony…….

App/appkarnal.php

Resourse/view/base.html.twig

src/send/sendmail/resourse/config/routing.yml

—————————————————————–

for layout

Symfony/vender/symfony/symfony/src/symfony/Bundle/Twigbundle/Resouces/view/layout.html.twig

<!DOCTYPE html>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset={{ _charset }}”/>
<meta name=”robots” content=”noindex,nofollow” />
<title>{% block title %} Symfony Test website

{% endblock %}</title>
<link href=”{{ asset(‘bundles/framework/css/structure.css’) }}” rel=”stylesheet” type=”text/css” media=”all” />
<link href=”{{ asset(‘bundles/framework/css/body.css’) }}” rel=”stylesheet” type=”text/css” media=”all” />

<link rel=”stylesheet” href=”{{ asset(‘bundles/framework/css/css.css’) }}” type=”text/css” />
<link rel=”stylesheet” href=”{{ asset(‘bundles/framework/css/css1.css’) }}” type=”text/css” />
<link rel=”stylesheet” href=”{{ asset(‘bundles/framework/css/css2.css’) }}” type=”text/css” />
<link rel=”stylesheet” href=”{{ asset(‘bundles/framework/css/css3.css’) }}” type=”text/css” />
<link rel=”stylesheet” href=”{{ asset(‘bundles/framework/css/css4.css’) }}” type=”text/css” />
<link rel=”stylesheet” href=”{{ asset(‘bundles/framework/css/css5.css’) }}” type=”text/css” />
<link rel=”stylesheet” href=”{{ asset(‘bundles/framework/css/css6.css’) }}” type=”text/css” />
<link rel=”stylesheet” href=”{{ asset(‘bundles/framework/css/css7.css’) }}” type=”text/css” />
<link rel=”stylesheet” href=”{{ asset(‘bundles/framework/css/css8.css’) }}” type=”text/css” />
<link rel=”stylesheet” href=”{{ asset(‘bundles/framework/css/css9.css’) }}” type=”text/css” />
<link rel=”stylesheet” href=”{{ asset(‘bundles/framework/css/css10.css’) }}” type=”text/css” />
<link rel=”stylesheet” href=”{{ asset(‘bundles/framework/css/css11.css’) }}” type=”text/css” />

<script language=”javascript” type=”text/javascript” src=”{{ asset(‘bundles/framework/js/js.js’) }}”></script>
<script language=”javascript” type=”text/javascript” src=”{{ asset(‘bundles/framework/js/js1.js’) }}”></script>
<script language=”javascript” type=”text/javascript” src=”{{ asset(‘bundles/framework/js/js2.js’) }}”></script>
<script language=”javascript” type=”text/javascript” src=”{{ asset(‘bundles/framework/js/js3.js’) }}”></script>
<script language=”javascript” type=”text/javascript” src=”{{ asset(‘bundles/framework/js/js4.js’) }}”></script>
<script language=”javascript” type=”text/javascript” src=”{{ asset(‘bundles/framework/js/js5.js’) }}”></script>
<script language=”javascript” type=”text/javascript” src=”{{ asset(‘bundles/framework/js/js6.js’) }}”></script>
<script language=”javascript” type=”text/javascript” src=”{{ asset(‘bundles/framework/js/js7.js’) }}”></script>
<script language=”javascript” type=”text/javascript” src=”{{ asset(‘bundles/framework/js/js8.js’) }}”></script>

{% block head %}{% endblock %}
</head>
<body>
<div id=”content”>
<div>
<div>

<img src=”data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAALYAAAA+CAMAAACxzRGDAAAAUVBMVEX////Ly8yko6WLioxkYmVXVVkwLjLl5eWxsLJKSEzy8vJxcHLY2Ni+vb89Oz9XVVh+fH+Yl5n///+xsbLY2Nlxb3KkpKWXlph+fX+LiYy+vr/IZP61AAAAAXRSTlMAQObYZgAABRBJREFUeNrVmtuWoyAQRS1FEEQSzQU7//+hYxUiXsKQZLJWM+chsUloN+WhCuguYoKyYqzmvGasKqH4HyRKxndipcgcumH8qViTM7TkUclcwaHmf5XM0eWq4km1KjdqXfMXJHVe1J3hL8lk5fCGv6wmT+o0d87U+XNrk0Y9nfv+7LM6ZJH5ZBL6LAbSxQ3Q5FDr22Skr8PQSy4n7isnsQxSX4r6pobhjCHHeDNOKrO3yGmCvZOjV9jmt8ulTdXFKdbKLNh+kOMvBzuVRa4Y7MUsdEUSWQe7xxCfZmcwjHU83LqzFvSbJQOXQvptbPnEFoyZtUUGwTeKuLuTHyT1kaP0P6cR01OKvv448gtl61dqZfmJezQmU/t+1R2fJLtBwXV6uWGwB9SZPrn0fKO2WAvQN1PUhHjTom3xgXYTkvlSKHs19OhslETq6X3HrXbjt8XbGj9b4Gi+lUAnL6XxQj8Pyk9N4Bt1xUrsLVN/3isYMug8rODMdbgOvoHs8uAb2fcANIAzkKCLYy+AXRpSU8sr1r4P67xhLgPp7vM32zlqt7Bhq2fI1Hwp+VgANxok59SsGV3oqdUL0YVDMRY7Yg8QLbVUU4NZNoOq5hJHuxEM28Sh/IyUZ8D3reR+yc58EGvOy2U0HQL6G9V+kWyEWHmzaMx6t4o9RhOm/riUiYrzqij4Ptqkn7AaCXqc+F47m04ahfde7YIz8RHEBN6BdVwdIGRVdNbKqYu1Hc0x0wBY4wqC8+XUgBGnj81SZsQB+0yAS1x/BlI/6ebHHk0lauQLuPDpu6EwAVJ7T0rl2uXa23jcqNyOZekhqYHRz3JOANrF4wCCmEs1f9D1lUe0n4NAATed80Y5e0Q7CO2TezM/BR6wKdgQzKbCF4uOQC3Bk0fKAzbFlyRWg3gksA/gmm7eOjrpaKX7fHlEW2xLbE6GZsPiCiShVzN7RG2xTz2G+OJtEqzdJ7APxy3MrSsV0VukXbKMp9lhs5BN6dr3CN+sySUaoxGwfRUM3I/gdPYONgVU+PLX4vUWm32AvUySarbONvcpV2RQEPKKjEBHFk01kQDGRblnn8ZuE9g+JUl8OWAPbkFK2K6JxhJVvF47FzYYnAN22ttwxKYCoH36rheEB7KG/HF/YUaa2G5JF+55tpyrl7B1WHM39HuP2N2EXPl1UBu8vbj4OjvD+NoTE4ssF+ScARgaJY1N7+u8bY/Y9BSM5PKwJbvMVab32YP5FB5TtcYVrGoASolVLTzI7kVsYVxRtAb5n2JXq1vCdtd47XtYItynrN0835PasLg0y13aOPbmPI+on2Lr9e5tjSHvgkAvclUjL3Fsdaw03IzgTR62yYClk7QMah4IQ0qSsoYYbOix6zJR1ZGDNMOY3Bb6W5S6jiyovep3t7bUPyoq7OkjYumrfESp8zSBc/OLosVf+nTnnKjsqR16++WDwpI8FxJWRFTlI6NKnqYJaL96TqjAbo9Toi5QiWBDcmfdFV+T8dkvFe5bItgstbM2X6QG2mVun+cazfRwOS0eiaeRRJKgLfc3BQAqfnhJyz8lfR6580SF/FXVu83Nz1xrrnFqqXL6Qxl47DNSm4RFflvN5sABDD8peouqLLKQXVdGbnqf+qIpOxON4ZyYdJEJ6sy4zS2c5eRPTT4Jyp46qDE5/ptAWqJOQ9e6yE82FXBbZCk1/tXVoshVoopE3CB0zmraI3nbqCJ/gW3ZMgtbC5nh/QHlOoOZBxQCRgAAAABJRU5ErkJggg==” alt=”Symfony” />
</div>

<div>
<form method=”get” action=”http://symfony.com/search” target=”_blank”>
<div>
<label for=”search-id”>
<img src=”data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAABUElEQVQoz2NgAIJ29iBdD0d7X2cPb+tY2f9MDMjgP2O2hKu7vS8CBlisZUNSMJ3fxRMkXO61wm2ue6I3iB1q8Z8ZriDZFCS03fm/wX+1/xp/TBo8QPxeqf+MUAW+QIFKj/+q/wX/c/3n/i/6Qd/bx943z/Q/K1SBI1D9fKv/AhCn/Wf5L5EHdFGKw39OqAIXoPpOMziX4T9/DFBBnuN/HqhAEtCKCNf/XDA/rZRyAmrpsvrPDVUw3wrkqCiLaewg6TohX1d7X0ffs5r/OaAKfinmgt3t4ulr4+Xg4ANip3j+l/zPArNT4LNOD0pAgWCSOUIBy3+h/+pXbBa5tni0eMx23+/mB1YSYnENroT5Pw/QSOX/mkCo+l/jgo0v2KJA643s8PgAmsMBDCbu/5xALHPB2husxN9uCzsDOgAq5kAoaZVnYMCh5Ky1r88Eh/+iABM8jUk7ClYIAAAAAElFTkSuQmCC” alt=”Search on Symfony website” />
</label>

<input name=”q” id=”search-id” type=”search” placeholder=”Search on Symfony website” />

<button type=”submit”>
<span>
<span>
<span>OK</span>
</span>
</span>
</button>
</div>
</form>
</div>
</div>

<div id=”ja-mainnav”>
<div>
<div>
<ul><li><a href=”/welcome” id=”menu1″ title=”Home”><span class=””>Home</span></a></li>
<li><a href=”/register” id=”menu37″ title=”Weekly Horoscope”><span class=””>Register User</span></a>
<li><a href=”/technology” id=”menu37″ title=”Weekly Horoscope”><span class=””>Technology</span></a>
<li><a href=”/industry” id=”menu37″ title=”Weekly Horoscope”><span class=””>Industries</span></a>
<li><a href=”/offering” id=”menu37″ title=”Weekly Horoscope”><span class=””>Offering</span></a>
<li><a href=”/aboutus” id=”menu37″ title=”Weekly Horoscope”><span class=””>About</span></a>
<li><a href=”/contactus” id=”menu37″ title=”Weekly Horoscope”><span class=””>Contact</span></a>
<li><a href=”/blog” id=”menu37″ title=”Weekly Horoscope”><span class=””>Blog</span></a>
<li><a href=”/career” id=”menu37″ title=”Weekly Horoscope”><span class=””>Careers</span></a>
<li><a href=”/news” id=”menu37″ title=”Weekly Horoscope”><span class=””>News</span></a>
<li><a href=”/admin” id=”menu37″ title=”Weekly Horoscope”><span class=””>Admin Login</span></a>
<li><a href=”/mail” id=”menu37″ title=”Weekly Horoscope”><span class=””>mail</span></a>

<script type=”text/javascript”>
var megamenu = new jaMegaMenuMoo (‘ja-mainnav’, {
‘bgopacity’: 0,
‘delayHide’: 1000,
‘slide’: 1,
‘fading’: 1,
‘direction’:’down’,
‘action’:’mouseover’,
‘tips’: false,
‘duration’: 300,
‘hidestyle’: ‘fastwhenshow’
});
</script>
</div>
</div>
<div style=”margin-left:5px;”><img  src=”{{ asset(‘bundles/framework/images/mobility.jpg’) }}”></div>

<div>
{% block body %}

{% endblock %}
</div>

<div>

<p style=”text-align: center;”><span style=”text-align: center;”>Home|News|Career|Trademark|Resources|Clients &amp; Alliances|Testimonial|Contact Us|Sitemap|Blog</span><br></p>

<p style=”text-align: center;”>
<span style=”text-align: center;”>Copyright &copy; 2012-2013  <a href=”http://www.symfony.com”>Symfony India</a>, Offshore Software Development – Software Outsourcing Company. All rights reserved</span>
</div>
</div>

</div>
</body>
</html>

index.html.twig

——————————-

{% extends “TwigBundle::layout.html.twig” %}

{% block body -%}

<div>
<form method=”post” action=”{{path(‘send_sendmail_homepage’)}}”>
<h2>Send Mail </h2>
<div>
<lavel>Name</level> &nbsp;&nbsp;&nbsp;&nbsp;
<input type=”text” value=”” name=”name”>
</div>
<div>
<lavel>First Name</level>
<input type=”text” name=”email” >
</div>

<div>
<lavel>Your Query</level>
<textarea name=”contact”></textarea>
</div>

<button type=”submit”>SignUp</button>

</form>

</div>
{% endblock %}

how to extend in twig template

{% extends “TwigBundle::layout.html.twig” %}

add javascript in twig

<script language=”javascript” type=”text/javascript” src=”{{ asset(‘bundles/framework/js/js3.js’)

add stylesheet

<link rel=”stylesheet” href=”{{ asset(‘bundles/framework/css/css8.css’) }}” type=”text/css” />

add images

<div style=”margin-left:5px;”><img  src=”{{ asset(‘bundles/framework/images/mobility.jpg’) }}”></div>

Where we palce images

Web/bundles/framework/images/

Web/bundles/framework/css

Web/bundles/framework/js

Thanks

Vinod Kumar maurya (Manager IT Carzonrent India Pvt Ltd  )

if you face any problem then you can write me

vinod.maurya1@gmail.com