Friday, December 17, 2010

Symfony Netbeans HelloWorld Tutorial

To day we will try to make a simple traditional "Hello World" application using the Symfony Framework in Netbeans, we will make this application from scratch, from configuring Symfony in Netbeans and then creating a module and so on, in a step by step manner.

Prerequisites

  • Symfony 1.4.x, you can download it form here
  • Netbeans with PHP support, you can download it from here
  • WAMP, you can download it from here
  • Little knowledge of PHP :)

Lets Start

Install Netbeans, WAMP server and then unzip Symfony and rename then extract folder to symfony (for simplicity). Now open Netbeans and go to Tools > Options > PHP (tab)


in PHP 5 interpreter filed browse to the PHP5 exe, which is located in %WAMP_INSTALL_DIR%\bin\php\php5.3.0\php.exe and below it there is an option for Global Include path in that Add the Folder of symphony (extracted one).

Now click on Symfony Tab

symfony tutorial

tell Netbeans where is Symfony Script is, it will be located in %SYMFONY_EXTRACTED_DIR%\data\bin\symfony notice it \bin\symfony with out any extension, click Ok button.

Now create a new PHP Project File > New Project... > PHP > PHP Application and press Next Button

symfony tutorial

name the project as HelloWorld and save the project in www directory of WAMP it will be %WAMP_INSTALL_DIR%\www\HelloWorld Click next button twice and you will see following screen.

symfony tutorial

check the Symfony PHP Web Framework  and click Finish. now Netbeans will create a Symfony Project with all the necessary configurations.

symfony tutorial

you will see a directory structure in Project window and a log of all the action taken by Netbeans, let run the project in a web browser, with following URL http://localhost/HelloWorld/web/

symfony tutorial

as you can see there is no CSS and images here, although Symfony is working, go to  %SYMFONY_EXTRACTED_DIR%\data\web and copy the sf folder and paste it in web directory of your project and refresh the page and you see a nice Welcome page.

symfony tutorial

now back to Netbeans, create a module mySite ,to do this  right click on Project > Symfony > Run Command ...

symfony tutorial

this will open a command console with all the command that Symfony support and it contains all the documentation associated with a command. we will use the generate:module command, we don't need to write the whole we just select the command form the list and provide parameters in the parameter filed in our case we pass frontend mySite telling symfony to create mySite module in fronted module. press Run Command.

symfony tutorial

now if you see your directory structure you will notice a module mySite is created with its action (Controller) and templates (View) folder and a default files are also created.

symfony tutorial

now open actions.class.php in actions folder and replace method executeIndex(sfWebRequest $request) with following code.
public function executeIndex(sfWebRequest $request)
  {
    $this->greetings="Hello World, Symfony is Great :)";
  }
now open indexSuccess.php located in templates folder this file is by defualt empty, in it paste the following code
<?php
    echo "

$greetings

"; ?> 
open web browser and navigate to the URL http://localhost/HelloWorld/web/frontend_dev.php/mySite it will also show a debugging toolbar which show very useful information, if you don't want debugging toolbar change URL to http://localhost/HelloWorld/web/index.php/mySite you should be able to see following page.

symfony tutorial
simple isn't it? :)

Note: there may be other ways, better ways of doing this, if you know such ways share them, this is the way i learn it .

8 comments:

shagilani on January 6, 2011 at 7:37 AM said...

Good job dude.. :)

Anonymous said...

Nice tutorial.
You save my time.
thx

Originative on April 4, 2011 at 12:53 PM said...

you are welcome :)

Anonymous said...

one more good Symfony video tutorial:
http://www.youtube.com/watch?v=OT8PAfJCPwE

Patricia said...

The content is useful, but the website is slow.
I lost more time to reach this page than I save in learning.

Anonymous said...

That's great hint, it helps me lots.
Thanks

Tony

Mihir said...

Nice tutorial... Keep up the good work...

Bilal Khan said...

Thanx alot for sharing this.... Its really helpful.... I was searching for the symfony tutorials..... this is a good effort from your side.... If you kindly attach other tutorials related to symfony.... It will be very helpful for us....

Post a Comment

 

Blog Info

A Pakistani Website by Originative Systems

Total Pageviews

Tutorial Jinni Copyright © 2015 WoodMag is Modified by Originative Systems