发新话题
打印

[转贴][原创中文翻译]symfony askeet 24:第一天,开始项目。

[转贴][原创中文翻译]symfony askeet 24:第一天,开始项目。

[欢迎转载,转载请注名出处http://watir.cn。本文英文版权归symfony官方网站所有]
第一天:开始项目
The project
项目开始
(译者:个人感觉,程序开发前期设计是很重要的,所以把项目基本介绍翻译一下。)
The application to be designed could have been a trivial“show-and-tell” application, like a to-do list, a phone book, or abookstore. But we want to use symfony on an original project, somethinguseful, with numerous features and an important size. The goal isreally to prove that symfony can be used in complex situations, todevelop professional applications with style and little effort.
这个程序被设计成“分享与告知”的功能,把你想知道的答案列出来,把你想看到的照片展示出来,甚至像书店那样提供给你图书信息。我们使用symfony开发它,很有效,可以增加很多的功能。我们的目的是证明symfony真正可以被用来在综合要求下开发出专业的、有风格的、不费劲的网站程序。
We also hope that lots of people will actually use theapplication, in order to show that a symfony website can support animportant load. That’s why the application needs to bring an actualservice, and to answer an existing need - or to create a new one. Thelaunch of the website will be a live stress test; this also means thatwe will need you, humble readers, to digg/bookmark/blog the site andtalk about it in real life to check how many visits it can support.
为了支持symfony,我们也希望很多人能真正使用一下这个程序。这也是为什么程序需要提供实用服务,包括回答现实问题-或创建一个新问题。网站的发布需要一个现场压力测试;意思是我们也需要你的参与,需要广大读者来顶、来收藏网摘、在本网站上写blog、讨论现实生活中的问题,看看askeet网站能支持多少读者。
The content of the project will be kept secret for another day.We still have much to do today without describing a full-featured web2.0 application. This should give you some time to argue and launchadditional hypothesis. However, we need a name, so let’s call it:askeet.
网站开发项目的具体内容今天还需要保密。今天我们除了描述Web2.0程序所有特性外还有很多事情要做。也需要给你一些时间来讨论和实现一些附加功能。因此,我们需要一个名字,就叫他:askeet。
(译者:symfony的安装就不翻译了,本文程序开发环境使用windows XP+SP2+wamp,pear安装symfony。)
Project Setup
建立项目
In symfony, applications sharing the same data model areregrouped into projects. For the askeet project, we can alreadydisclose the fact that there will be a frontend and a backend: thatmakes two applications. The project being the shell of theapplications, it has to be created first. To do that, all you need is adirectory and a symfony init-project command line:
symfony里使用同样数据模块的应用程序(app)被重组进项目。对于askeet网站项目来说,可以肯定有一个前台和一个后台:那么就是两个app。项目从外面看起来就是这两个app的,首先建立项目。你需要一个目录和一句命令来执行。
复制内容到剪贴板
代码:
$ mkdir /home/sfprojects/askeet

$ cd /home/sfprojects/askeet

$ symfony init-project askeet
Now it is time to create the frontend application with the symfony init-app command:
现在用命令创建前台frontend:
复制内容到剪贴板
代码:
$ symfony init-app frontend
Wow, that was fast.
哦,很快!
Windows users are advised to run symfony and to setup their newproject in a path which contains no spaces - this includes theDocuments and Settings directory.
建议windows用户把项目创建在不包含空格的路径下,就是说文件路径不要有空格。
Web service setup
打造web服务器
Web server configuration
web服务器配置
Now it is time to change your Apache configuration to make thenew application accessible. In a professional context, it is better tosetup a new application as a virtual host, and that’s what will bedescribed here. However, if you prefer to add it as an alias, find howin the web server configuration cookbook chapter.
改变你的apache配置来让你的新程序可用。专业点说法就是,最好把新的程序弄成虚拟主机,这里就来介绍一下。因此,如果你想玩点别的,参考the new server configuration cookbook章节。
Open the httpd.conf file of your Apache/conf/ directory and add at the end:
打开httpd.conf(apache/conf),把这些加在后面:
复制内容到剪贴板
代码:
<VirtualHost *:80>

ServerName askeet

DocumentRoot "/home/sfprojects/askeet/web"

DirectoryIndex index.php

Alias /sf /usr/local/lib/php/data/symfony/web/sf





<Directory “/home/sfprojects/askeet/web”>

AllowOverride All

</Directory>

</VirtualHost>
##########################################
(译者:实际在windows下,我是这么改的。)
由于在windows下,需要做相应修改:
复制内容到剪贴板
代码:
<VirtualHost *:80>

DocumentRoot "c:/wamp/www/askeet/web"

ServerName askeet

DirectoryIndex index.php

Alias /sf "c:\wamp\php\pear\data\symfony\web\sf"

<Directory "c:/wamp/www/askeet/web">

AllowOverride All

</Directory>

</VirtualHost>
##########################################
(译者:经过实际使用,发现在windows下的一个小特点,安装好wamp后,如果把askeet目录放在www下,那么上面一切都正常;但是如果放在别的位置,例如:c:\askeet,那么在浏览器里运行会出现权限authorization问题(提示403错误)。我初步猜测是wamp安装好后在windows下把www目录权限设置好了,其他的目录internet来宾访问权限没有加上,如果以前做过IIS设置的应该想起来了。当然这是个人的一点看法,如果有不同意见,请留言指教。)
(译者:2007年国庆节那天,当我把碰到的问题告诉一个朋友——“蚂蚱”后,他跑到我的笔记本前,兴致勃勃的调试起来。他把apache的httpd.conf加了权限,把我的代码改为:
复制内容到剪贴板
代码:
<VirtualHost *:80>

DocumentRoot "c:/askeet/web"

ServerName askeet

DirectoryIndex index.php

Alias /sf "c:\wamp\php\pear\data\symfony\web\sf"





<Directory “c:/askeet/web”>

Options Indexes FollowSymLinks

AllowOverride All

Allow from all

</Directory>





<Directory “c:\wamp\php\pear\data\symfony\web\sf”>

Options Indexes FollowSymLinks

AllowOverride All

Allow from all

</Directory>





</VirtualHost>
注意看,他给“c:/askeet/web”加了权限,也给“c:\wamp\php\pear\data\symfony\web\sf”加了权限,然后运行symfony cc(清除缓存),哈哈一切都OK了!在此谢谢蚂蚱的帮助!)
##########################################
the /sf alias has to point to the symfony folder in your PEARdata directory. To determine it, just type pear config-show. Symfonyapplications need to have access to this folder to get some image andjavascript files, to properly run the web debug toolbar and the AJAXhelpers.
/sf指出了在PEAR目录下symfony所在。为了实现这个,输入pear config-show。symfony程序需要登入此目录获取图片和javascript,然后才能完美运行web debug工具条和AJAX helpers。
In Windows, you need to replace the Alias line by something like:
windows下,你需要把Alias那一行换成这样:
Alias /sf "C:\php\pear\data\symfony\web\sf"
Declare the domain name
声明主机名
The domain name askeet has to be declared locally.
需要在本地声明askeet主机名。
If you run a Linux system, it has to be done in the /etc/hostsfile. If you run Windows XP, this file is located in theC:\WINDOWS\system32\drivers\etc\ directory.
如果在linux下,需要修改/etc/hosts文件。在windows XP下,文件在c:\windows\system32\drivers\etc下。
Add in the following line:
继续添加:
复制内容到剪贴板
代码:
127.0.0.1         askeet
you need to have administrator rights to do this.
做这些你需要administrator权限。
If you don’t want to setup a new host, you should add a Listenstatement to serve your website on another port. This will allow you touse the localhost domain.
如果你不想建立一个新主机,你需要修改服务器配置监听其他端口。这样就可以让你使用localhost domain。
Test the new configuration
测试一下新配置是否通过
Restart Apache, and check that you now have access to the new application:
重启apache,检查新程序运行情况。
http://askeet/

symfony can use the mod_rewrite module to remove the /index.php/part of the URLs. If you don’t want to use it or if your web serverdoes not provide an equivalent facility, you can remove the .htaccessfile located in the web/ directory. If your version of Apache is notcompiled with mod_rewrite, check that you have the mod_rewrite DSOinstalled and the following lines in your httpd.conf:
symfony可以使用url重写(mod_rewrite)模块来去除URL中的/index.php/部分。如果你不想使用或者你的web服务没有提供同样的支持,你可以删除.htaccess文件,就在web目录下。如果你的apache版本不能编译mod_rewrite,检查mod_rewrite DSD安装和修改httpd.conf:
复制内容到剪贴板
代码:
AddModule mod_rewrite.c

LoadModule rewrite_module modules/mod_rewrite.so
You will learn more about the smart URLs in the Links and the Routing System chapter.
在symfony手册路由章节你会学到更多。
You should also try to access the application in the development environment. Type in the following URL:
你可以在开发环境中连接程序并调试。输入下面的URL:
http://askeet/frontend_dev.php/
The web debug toolbar should show on the top right corner,including small icons proving that your Alias sf/ configuration iscorrect.
web debug工具条显示在右上,小图标显示你的程序运行情况。

Once again, the setup is a little different if you want to run aIIS server in a Windows environment. Find how to configure it in therelated tutorial.
再一次,如果在windows下你使用IIS的话,配置会有不同。参考其他教程
(译者:后面的svn就不翻译了。)

TOP

发新话题