手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆

Zend framework quickstart -> create project

首页 > PHP Framework >

仍然是quickstart的内容之一:create project

Create Your Project

In order to create your project, you must first install Zend Framework.


Install Zend Framework

The easiest way to get Zend Framework along with a complete PHP stack is by installing Zend Server. Zend Server has native installers for Mac OSX, Windows, Fedora Core, and Ubuntu, as well as a universal installation package compatible with most Linux distributions.

最简单安装ZF的方法就是安装ZendServer,ZendServer可以安装在苹果系统,windows, fedora,ubuntu,而且支持大多数的linux操作系统 。

After you have installed Zend Server, the Framework files may be found under /Applications/ZendServer/share/ZendFramework on Mac OSX, C:\Program Files\Zend\ZendServer\share\ZendFramework on Windows, and /usr/local/zend/share/ZendFramework on Linux. The include_path will already be configured to include Zend Framework.

在你安装完zendserver后,如果您是使用MAC系统,你将在/Applications/ZendServer/share/ZendFramework目录下找到框架文件,windows平台的话,是在, C:\Program Files\Zend\ZendServer\share\ZendFramework目录中,而linux平台则在/usr/local/zend/share/ZendFramework目录中。同时include_path也已经被配置好支持ZF框架了。

Alternately, you can download the latest version of Zend Framework and extract the contents; make a note of where you have done so.


Optionally, you can add the path to the library/ subdirectory of the archive to your php.ini's include_path setting.


That's it! Zend Framework is now installed and ready to use.



zf Command Line Tool ZF命令行工具
  1. In your Zend Framework installation is a bin/ subdirectory, containing the scripts and zf.bat for Unix-based and Windows-based users, respectively. Make a note of the absolute path to this script.  
  2. 在你的ZF安装目录下,有两个可执行文件:zf.sh和zf.bat,他们分别对应着Unix平台和windows平台。记录下这个文件的绝对路径  
  4. Wherever you see references to or zf.bat, please substitute the absolute path to the script. On unix-like systems, you may want to use your shell's alias functionality: alias  
  5. 当你想要引用这zf.sh或者zf.bat文件 的时候,请先设置它的详细路径。例如在Unix平台下,你可以使用shell功能来进行替代:alias  
  7. If you have problems setting up the zf command-line tool, please refer to the manual.  
  8. 如果你还对ZF命令行工具有疑问,那就只能查看官方的手册了  

Open a terminal (in Windows, Start -> Run, and then use "cmd"). Navigate to a directory where you would like to start a project. Then, use the path to the appropriate script, and execute one of the following:




  1. # Unix:  
  2. % create project quickstart  
  4. # DOS/Windows:  
  5. C:> zf.bat create project quickstart  

Running this command will create your basic site structure, including your initial controllers and views. The tree looks like the following:


运行了这个命令,你将会得到ZF框架的项目的最基本结构,包含了初始化后的控制和和视图(controllers and vews),这个树形结构类似如下:

  1. quickstart  
  2. |-- application  
  3. |   |-- Bootstrap.php  
  4. |   |-- configs  
  5. |   |   `-- application.ini  
  6. |   |-- controllers  
  7. |   |   |-- ErrorController.php  
  8. |   |   `-- IndexController.php  
  9. |   |-- models  
  10. |   `-- views  
  11. |       |-- helpers  
  12. |       `-- scripts  
  13. |           |-- error  
  14. |           |   `-- error.phtml  
  15. |           `-- index  
  16. |               `-- index.phtml  
  17. |-- library  
  18. |-- public  
  19. |   `-- index.php  
  20. `-- tests  
  21.     |-- application  
  22.     |   `-- bootstrap.php  
  23.     |-- library  
  24.     |   `-- bootstrap.php  
  25.     `-- phpunit.xml  


At this point, if you haven't added Zend Framework to your include_path, we recommend either copying or symlinking it into your library/ directory. In either case, you'll want to either recursively copy or symlink the library/Zend/ directory of your Zend Framework installation into the library/ directory of your project. On unix-like systems, that would look like one of the following:

在这点中,如果你没有将ZF框架加入到你的 include_path ,我们推荐你将它 COPY或者 symlinking到你的 library目录下。两种方法其中都是将library/Zend 目录 链至你的项目。在unlx系统中,它大致是这样操作的:

  1. # Symlink:  
  2. % cd library; ln -s path/to/ZendFramework/library/Zend .  
  4. # Copy:  
  5. % cd library; cp -r path/to/ZendFramework/library/Zend .  

On Windows systems, it may be easiest to do this from the Explorer.



Now that the project is created, the main artifacts to begin understanding are the bootstrap, configuration, action controllers, and views.

项目创建完毕后,the main artifact【不知道如何翻译】先了角解一下:bootstrap,configuration,action,controllers和views

The Bootstrap

Your Bootstrap class defines what resources and components to initialize. By default, Zend Framework's Front Controller is intialized, and it uses the application/controllers/ as the default directory in which to look for action controllers (more on that later). The class looks like the following:

Bootstrap类定义了资源和构成的初始化。默认情况下ZF只初始化了Front Controller【前端操作器】,它使用了 application/controllers 作为默认目录,在该目录里有着controller控制类的文件。bootstrap最初是这样的:

  1. class Bootstrap extends Zend_Application_Bootstrap_Bootstrap  
  2. {  
  3. }  

As you can see, not much is necessary to begin with.



While Zend Framework is itself configurationless, you often need to configure your application. The default configuration is placed in application/configs/application.ini, and contains some basic directives for setting your PHP environment (for instance, turning error reporting on and off), indicating the path to your bootstrap class (as well as its class name), and the path to your action controllers. It looks as follows:


  1. ; application/configs/application.ini  
  3. [production]  
  4. phpSettings.display_startup_errors = 0  
  5. phpSettings.display_errors = 0  
  6. includePaths.library = APPLICATION_PATH "/../library"  
  7. bootstrap.path = APPLICATION_PATH "/Bootstrap.php"  
  8. bootstrap.class = "Bootstrap"  
  9. resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"  
  11. [staging : production]  
  13. [testing : production]  
  14. phpSettings.display_startup_errors = 1  
  15. phpSettings.display_errors = 1  
  17. [development : production]  
  18. phpSettings.display_startup_errors = 1  
  19. phpSettings.display_errors = 1  
Several things about this file should be noted. First, when using INI-style configuration, you can reference constants directly and expand them; APPLICATION_PATH is actually a constant. Additionally note that there are several sections defined: production, staging, testing, and development. The latter three inherit settings from the "production" environment. This is a useful way to organize configuration to ensure that appropriate settings are available in each stage of application development.














本站采用创作共享版权协议, 要求署名、非商业和保持一致. 本站欢迎任何非商业应用的转载, 但须注明出自"膘叔", 保留原始链接, 此外还必须标注原文标题和链接.

« 上一篇 | 下一篇 »


评论内容 (必填):