Date post: | 30-May-2018 |
Category: |
Documents |
Upload: | navindersharma |
View: | 216 times |
Download: | 0 times |
of 32
8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
1/32
8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
2/32
4. As per output please set short_open_tag and magic_quoted_gpc to off by editing php.ini.Open file by typing following command in Terminal window:
$ sudo gedit /etc/php5/apache2/php.ini
Make the changes as following, then save the file and exit.
8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
3/32
5. Please restart your Apache with following command:
$ sudo /etc/init.d/apahe2 restart
6. Again visit check_configuration url in your web browser usinghttp://localhost/check_configuration.php. The output must look like below:
http://localhost/check_configuration.phphttp://localhost/check_configuration.php8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
4/32
7. For installation of Symfony on Ubuntu linux. Please download symfony-1.2.10.tgz fromhttp://www.symfony-project.org/installation /1_2. Unzip the folder by right click and Extract
Here option. Copy unzipped folder in Document Root of your system i.e. public_html as
shown below:
8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
5/32
8. Please start NetBeans by clicking Applications Programming NetBeans IDE 6.8. Clickon options Tools Options shown below:
8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
6/32
9. Click on PHP General and see that you PHP 5 Interpreter will look like as follows:
10. Then click on Symfony tab, and set path to bin directory of symfony as shown below:
8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
7/32
11.Now its time to set keyboard shortcuts to Symfony Command Box and Clear Cachecommand 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 OKbutton on the following screen, to set theshortcut forSymfony: Run Command.
8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
8/32
13. symfony cc is the command we use most frequently. Thats why we are going to assignkeyboard 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 andClick on File New Project. Creation of this project starts with following screen. Please
click on PHP PHP Application and Next button.
8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
9/32
15.Next screen will ask forProject Name give it myfirstproject. This tutorial is same as MyFirst Project given on Symfonys 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:
http://www.symfony-project.org/get/pdf/my-first-project-1.2-en.pdfhttp://www.symfony-project.org/get/pdf/my-first-project-1.2-en.pdfhttp://www.symfony-project.org/get/pdf/my-first-project-1.2-en.pdfhttp://www.symfony-project.org/get/pdf/my-first-project-1.2-en.pdfhttp://www.symfony-project.org/get/pdf/my-first-project-1.2-en.pdf8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
10/32
17. On next screen, please select Symfony PHP Web frameworkand give csrf-secret as I havegiven navinder123. Click on Finish button.
18. This will create a lot of directories as follows:
8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
11/32
19. Please click on myfirstproject and press Alt+L. This will give you symfony command box.Please type configure in Filter box. Click on configure:database in Matching Tasks and
give pgsql:dbname=myfirstproject;host=localhost postgres postgres in Parameters.
In above string:
a. pgsql is driver to PostgreSQL
b. myfirstproject is database you have in your postgresql
c. host host on which you are creatingd. postgres is username
e. postgres is password
You should create your myfirstproject database by opening pgAdmin III. The screen for
configure:database will look like as following:
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:
8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
12/32
21.Now open /myfirstproject/config/schema.yml and create schema of your project asfollowing. Please take care of indentation and dont 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.
8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
13/32
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 foldermodel 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 setmethods 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:
8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
14/32
24.Now model is ready, you can create SQL from it by using propel:build-sql. Please pressAlt+L and give propel:build-sql command as following:
8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
15/32
25. Above command will create a file lib.model.schema.sql in /myfirstproject/data/sql whichholds 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+Land give command. NetBeans will ask for confirmation message. Please press Y there.
8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
16/32
8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
17/32
27. Above command will create two tables i.e. blog_comment and blog_post in yourPostgreSQL. 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:
8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
18/32
29. Above command will create form folder in /myfirstproject/lib folder of project. Aswe 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
Please press Alt+C to clear cache.
8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
19/32
31. Above two commands will create two modules (i.e. two directories) in/myfirstproject/apps/frontend/modules as following:
8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
20/32
32. Each directory here contains two folders one is actions and another is templates.Actions folder contains Controller and templates contain View of the module. Two folders in
post are shown as following:
33. Now the project is ready, we have to setup our web server. Please create an alias ofmyfirstproject 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.
8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
21/32
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:
36. Now give this url: http://localhost/myfirstproject/frontend_dev.php/post. You will seeit is displaying contents of your blog_post table.
http://localhost/myfirstproject/frontend_dev.phphttp://localhost/myfirstproject/frontend_dev.php/posthttp://localhost/myfirstproject/frontend_dev.phphttp://localhost/myfirstproject/frontend_dev.php/post8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
22/32
37. If we look at url we are using frontend_dev.php in it. What is it? It is frontcontroller to the development environment of Symfony. Symfony supports different
environments for different purposes:
The development environment: This is the environment used by web developers
when they work on the application to add new features, fix bugs etc.
(frontend_dev.php)
The test environment: This environment is used to automatically test the
application.
The production environment: This is the environment end users interact with.
(index.php)
38. In step 36, you are giving http://localhost/myfirstproject/frontend_dev.php/post.By default when we give a url it is as modulename/actionnamebut in above url you are
only giving module name i.e. post. When you do this Symfony will automatically take it as
post/index that means it is invoking index action ofpost module. It will go to controller (i.e.
/myfirstproject/apps/frontend/modules/post/actions/actions.class.php) of the post module
and go for executeIndex() function.
39. As mentioned in above step in executeIndex() function, it will put the contents ofblog_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:
http://localhost/myfirstproject/frontend_dev.php/posthttp://localhost/myfirstproject/frontend_dev.php/posthttp://localhost/myfirstproject/frontend_dev.php/post8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
23/32
8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
24/32
41. After that click on Cancel to see the saved contents. The screen will look like as
following:
42. In next step. Please open second url as:http://localhost/myfirstproject/frontend_dev.php/comment
Now click on New link. You will get an error like as following:
8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
25/32
8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
26/32
44. Refresh the page in step 42, You will get the comment form 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:
8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
27/32
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:
http://localhost/myfirstproject/frontend_dev.php/commenthttp://localhost/myfirstproject/frontend_dev.php/comment8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
28/32
49. Open the url given in step 47 again in browser and see the effect. The screen will look like asfollowing:
50.Now its time to create a starting module. Please create a new module by pressing Alt+L andgive command:
generate:module frontend main
8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
29/32
51. Please delete single line in executeIndex() ofactions.class.php in/myfirstproject/apps/frontend/modules/main/actions. The screen will look like as
following:
52. Please change indexSuccess.php of/myfirstproject/apps/frontend/modules/main/templates to give a welcome message as
following:
8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
30/32
53.Now set your starting module by editing /myfirstproject/apps/frontend/config/routing.yml
Change homepage as module: main. The file 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
8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
31/32
55.Now project is ready. Its time to package the project for deployment. To package the projectuse following command:
project:freeze /home//public_html/symfony-1.2.10/data/binThe screen for above command is below:
8/14/2019 Developing With Symfony1.2 and NetBeans6.8 in Ubuntu Linux
32/32
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. Thats all the application is finished. With this tutorial I want to tell you about how todevelop 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.