如何在 Windows 上安装 Zend 框架 [英] How to install Zend Framework on Windows

查看:30
本文介绍了如何在 Windows 上安装 Zend 框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

安装 Zend Framework 太简单了!!!"对对对...

"installing Zend Framework is so easy!!!!" yeah right...

好的,我正在写一本初学者的书,没有过于详细的一件事是最重要的部分:安装该死的东西.浏览了几个小时的快速入门指南后,它说的是:

Ok I'm working with a beginner's book and the ONE thing that is not excessively detailed is the most important part: Installing the darn thing. After browsing the quickstart guide for hours, all it said was:

下载 Zend [...] 添加包含目录 (bla bla) 就大功告成了!"

"download Zend [...] add the include directory (bla bla) and YOU'RE DONE!"

好的,我已经用完了 Zend.

right, i'm done using Zend.

好吧,不是真的,反正还不是.我求求你们,我想睡觉了,请告诉我如何(简单的六年级细节)安装框架.我的 htdocs 目录中有解压后的文件夹,我把 zf.bat+zf.php 放在 htdocs 根目录下.

Ok, not really, not yet anyway. I beg of you people, I wanna go to bed, please tell me how (in simple 6th grade detail) to install the framework. I've got the unzipped folder in my htdocs directory, and I placed zf.bat+zf.php in the htdocs root.

接下来是什么?

非常感谢.

推荐答案

您似乎在使用 Windows 命令外壳中的 PATH 时遇到了问题.这独立于 Zend 框架.理解 shell 环境中的 PATH 概念是许多程序员必须克服的障碍,但是一旦掌握了它,就可以使用它来提高生产力.

It seems like you're having trouble with the PATH in the Windows command shell. This is independent of Zend Framework. Understanding the PATH concept in a shell environment is a hurdle many programmers have to overcome, but once you get it, you can use it to increase your productivity.

您始终可以使用该程序的绝对路径从命令外壳运行该程序.例如:

You can always run a program from the command shell using that program's absolute path. For example:

C:\> c:\wamp\bin\php\php.exe

您还可以使用相对路径运行命令.也就是说,您输入从当前工作目录到要运行的程序所在位置的路径.

You can also run a command using a relative path. That is, you enter the path from your current working directory to the location of the program you want to run.

C:\> cd c:\wamp
C:\> bin\php\php.exe

但是如果您在命令 shell 中运行命令没有命名可执行文件的完整路径,shell 会尝试在 PATH<中列出的目录之一中查找程序可执行文件/code> 环境变量.也就是说,路径是一个目录名用分号分隔的字符串.要运行可执行文件,shell 会按顺序尝试该列表中的每个目录,就好像您已经

But if you run a command in the command shell without naming the full path to the executable, the shell tries to find the program executable in one of the directories listed in your PATH environment variable. That is, the path is a string with directory names separated by semicolons. To run an executable, the shell tries each directory in that list, in order, as if you had

C:\> type %PATH%
C:\WINDOWS\;C:\WINDOWS\SYSTEM32
C:\> php.exe
...error that it cannot find php.exe...

特殊情况:如果您当前的工作目录恰好是该程序可执行文件的位置,则运行 php.exe 也有效.但这只是使用相对路径的一个例子,使用零目录级别的路径.

Special case: running php.exe also works if your current working directory happens to be the location of that program executable. But that's just an example of using a relative path, using a path with zero directory levels.

第二个问题是您正在运行 zf.bat,它是一个脚本,它会在不指定路径的情况下调用 php.exe.它假定您已将 php.exe 的位置添加到您的 PATH 环境变量中.

Second problem is that you're running zf.bat which is a script that in turn invokes php.exe without specifying a path. It assumes you have added the location of php.exe to your PATH environment variable.

C:\> SET PATH=%PATH%;C:\wamp\bin\php
C:\> php.exe -v
PHP 5.3.1 (cli) (built: Nov 29 2009 13:59:20) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies

zf.bat 脚本本身也需要找到.您可以通过将它所在的目录添加到您的 PATH 中来完成此操作.假设您在 C:\zf 下安装了 Zend Framework,例如:

The zf.bat script itself also needs to be found. You can do this by adding the directory where it resides to your PATH. Assuming you installed Zend Framework under C:\zf, for example:

C:\> type %PATH%
C:\WINDOWS\;C:\WINDOWS\SYSTEM32;C:\wamp\bin\php
C:\> zf.bat
...error that it cannot find zf.bat...
C:\> SET PATH=%PATH%;C:\zf\bin
C:\> zf.bat show version
Zend Framework Version: 1.10.0dev

我还建议您在 htdocs 目录外部安装 Zend Framework.您的 htdocs 下只需要一个 PHP 文件:它是 Zend Framework 用于实例化前端控制器和分派请求的单个引导文件.

I would also recommend that you install Zend Framework outside your htdocs directory. There's only one PHP file you need under your htdocs: that is the single bootstrap file that Zend Framework uses to instantiate the Front Controller and dispatch the request.

当您使用 zf.bat 为您生成一个框架应用程序时,它会创建一个目录 public,其中包含一个 PHP 脚本 index.php在那个目录里面.此 index.php 文件是您需要位于 htdocs 目录中的文件.您还需要将 CSS、Javascript 和图像等资产放在 htdocs 下.您的应用程序代码的其余部分以及整个 Zend 框架本身应该您的htdocs 之外.尤其是您存储敏感数据(例如数据库密码等)的任何配置文件.

When you use zf.bat to generate an skeleton application for you, it creates a directory public with a PHP script index.php inside that directory. This index.php file is the one you need to be in your htdocs directory. You also need assets like CSS, Javascript, and images to be under your htdocs. The rest of your application code, and the entire Zend Framework itself, should be outside your htdocs. Especially any config files where you store sensitive data such as your database password, etc.

您可以编辑 index.php 文件.它可以定义一个 PHP 常量 APPLICATION_PATH,它是应用程序其余代码的位置.

You can edit the index.php file. It may define a PHP constant APPLICATION_PATH, which is the location of the rest of your application code.

<?php

defined("APPLICATION_PATH")
    || define("APPLICATION_PATH", realpath(dirname(__FILE__) . "/../application"
));

APPLICATION_PATH 的默认定义假定您的 htdocs 是由 zf.bat 生成的其余应用程序代码的姊妹目录工具.你当然可以把你的应用代码放在其他地方,但你必须改变上面的代码,以便 index.php 脚本找到它.

That default definition for APPLICATION_PATH assumes that your htdocs is a sister directory to the rest of your application code generated by the zf.bat tool. You can certainly put your app code anywhere else, but you have to change the above code so that the index.php script finds it.

index.php 脚本也可以将库代码的位置添加到 PHP 的 INCLUDE_PATH 中.如果您需要使 Zend Framework 库可找到,或者如果您在应用程序中使用其他第三方 PHP 代码,这将非常有用.假设您在 C:\zf 下安装 Zend Framework,您应该将其 library 子目录添加到您的 PHP INCLUDE_PATH.

Also the index.php script may add the location of library code to PHP's INCLUDE_PATH. This is useful if you need to make the Zend Framework library findable, or if you use other third-party PHP code in your application. Assuming you installed Zend Framework under C:\zf, you should add its library subdirectory to your PHP INCLUDE_PATH.

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    "C:/zf/library",
    realpath(APPLICATION_PATH . "/../library"),
    get_include_path()
)));

zf.bat 脚本生成的代码模板尝试对您的代码所在的位置进行合理的默认猜测,但您的环境是您自己的,并且很容易编辑这些脚本以指定您安装代码和库的真实位置.

The code templates generated by the zf.bat script try to make sensible default guesses about where your code is located, but your environment is your own, and it's easy to edit these scripts to specify the true location where you installed your code and libraries.

这篇关于如何在 Windows 上安装 Zend 框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆