Professional Documents
Culture Documents
1. If you have gone through my first tutorial on Ubuntu i.e. ‘Installing PHP development
environment in Ubuntu’ then go to step 2 otherwise please check out first tutorial then
move forward.
Make the changes as following, then save the file and exit.
5. Please restart your Apache with following command:
$ sudo /etc/init.d/apahe2 restart
10. Then click on Symfony tab, and set path to bin directory of symfony as shown below:
11. Now its time to set keyboard shortcuts to Symfony Command Box and Clear Cache
command which we run most frequently. Click on Keymap and type run in Search box, it
will show Symfony: Run Command in Actions below. Please select the text and Press …
button in front of text and select Edit as shown below:
12. Press ‘Alt+L’ from keyboard and then press OK button on the following screen, to set the
shortcut for Symfony: Run Command.
13. symfony cc is the command we use most frequently. That’s why we are going to assign
keyboard shortcut to that also. Please click on Keymap and this time type clear cache in
Search box it will Symfony: Clear Cache in Actions. Please select and assign ‘Alt+C’ to this
as shown below:
14. Now your system is ready for development with Symfony and NetBeans. Start NetBeans and
Click on File New Project. Creation of this project starts with following screen. Please
click on PHP PHP Application and Next button.
15. Next screen will ask for Project Name give it myfirstproject. This tutorial is same as My
First Project given on Symfony’s website i.e. http://www.symfony-
project.org/get/pdf/my-first-project-1.2-en.pdf. Please note down Sources Folder it must
be Document Root of your Apache Server given as following:
16. Next screen will tell you about Run Configuration as following:
17. On next screen, please select Symfony PHP Web framework and give –csrf-secret as I have
given ‘navinder123’. Click on Finish button.
20. Above command will change your /myfirstproject/config/databases.yml. Look at your dsn,
username and password will changed according to configure:database command.
databases.yml will look like as following:
21. Now open /myfirstproject/config/schema.yml and create schema of your project as
following. Please take care of indentation and don’t use tab key while creating schema. First
you have to write connection name i.e. propel, then table names i.e. blog_post and
blog_comment further they hold fieldnames like blog_post has id, title, excerpt, body,
created_at.
22. Now schema is ready. Please create model from it. Press ‘Alt+L’ to invoke symfony
command box and run command:
propel:build-model
23. Above command will create a folder model in /myfirstproject/lib folder in project directory.
In model folder one each table has two classes one is object class that will hold get and set
methods and other is peer class this class includes database operations (i.e. insert, select,
delete). The files in /myfirstprojet/lib/model are blank, these files are for you, you can write
our customized code in these files. Take a look at created directories as below:
24. Now model is ready, you can create SQL from it by using propel:build-sql. Please press
‘Alt+L’ and give propel:build-sql command as following:
25. Above command will create a file lib.model.schema.sql in /myfirstproject/data/sql which
holds sql commands to create tables and set primary and foreign key given following:
26. SQL commands created in previous step will be executed by propel:insert-sql. Press ‘Alt+L’
and give command. NetBeans will ask for confirmation message. Please press ‘Y’ there.
27. Above command will create two tables i.e. blog_comment and blog_post in your
PostgreSQL. Please open pgAdmin III and see the tables in myfirstproject. It must be as
following:
28. Now your database and model is ready. Create forms using propel:build-forms.
Please press ‘Alt+L’ and give propel:build-forms as following:
29. Above command will create form folder in /myfirstproject/lib folder of project. As
we have discussed in Model creation each table create two forms one in base folder and other
outside base folder. You can customize form outside base folder according to your
requirement. Avoid customization of Base forms inside base folder because it will got
changed every time you execute propel:build-forms
30. Until now forms are ready. Now for database operation like Create, Read, Update,
Delete you have to create modules. Symfony has commands for that also, it will create your
CRUD operation automatically for you. Use following commands
propel:generate-module frontend post BlogPost
propel:generate-module frontend comment BlogComment
33. Now the project is ready, we have to setup our web server. Please create an alias of
myfirstproject by editing /etc/apache2/sites-available/mysite. Open Terminal window give
following command:
$ sudo gedit /etc/apache2/sites-available/mysite
Before last line please add following, Save the file and Exit.
34. Please restart Apache using following command:
$ sudo /etc/init.d/apache2 restart
35. Now web server is also ready. Open your browser and give url as:
http://localhost/myfirstproject/frontend_dev.php
Output must be as following:
39. As mentioned in above step in executeIndex() function, it will put the contents of
blog_post table in blog_post_list array and give the control to indexSuccess.php template to
display contents of blog_post_list. The indexSuccess.php will look like this:
40. Anyway open browser and give url as
http://localhost/myfirstproject/frontend_dev.php/post
Click on New link, Fill the form as following and click on Save button to save the contents of
form.
41. After that click on Cancel to see the saved contents. The screen will look like as
following:
45. Save the content and Click Cancel to see the saved contents.
46. Now its time to format the contents of the project. Please open
/myfirstproject/web/css/main.css and add some css classes as following into it:
47. Now again open browser and give url as:
http://localhost/myfirstproject/frontend_dev.php/comment
You can see the effect of css classes on next screen:
48. You can change the layout of the project with single file. Please open
/myfirstproject/apps/frontend/templates/layout.php and change the body part of
layout.php as following:
49. Open the url given in step 47 again in browser and see the effect. The screen will look like as
following:
50. Now its time to create a starting module. Please create a new module by pressing ‘Alt+L’ and
give command:
generate:module frontend main
51. Please delete single line in executeIndex() of actions.class.php in
/myfirstproject/apps/frontend/modules/main/actions. The screen will look like as
following:
:
54. Please clear cache by pressing ‘Alt+C’. Your application is ready, see it with :
http://localhost/myfirstproject/frontend_dev.php/main
You can navigate to List of Posts and List of Comments
55. Now project is ready. Its time to package the project for deployment. To package the project
use following command:
project:freeze /home/<user>/public_html/symfony-1.2.10/data/bin
The screen for above command is below:
56. Above command will add three folders i.e. /myfirstproject/data/symfony,
/myfirstproject/lib/symfony and /myfirstproject/web/sf into project as shown below. With
freeze command you are adding symfony library files to your project. Now your project
folder is ready to deploy.
57. That’s all the application is finished. With this tutorial I want to tell you about how to
develop a basic application using symfony and NetBeans. For detailed study you have to go
through Symfony book (http://www.symfony-project.org/get/pdf/book-1.2-en.pdf), Getting
Started (http://www.symfony-project.org/get/pdf/getting-started-1.2-en.pdf), My First Project
(http://www.symfony-project.org/get/pdf/my-first-project-1.2-en.pdf) and Forms in Action
(http://www.symfony-project.org/get/pdf/forms-1.2-en.pdf) given on Symfony website.