简体   繁体   English

PHP / Zend Framework路径问题

[英]PHP/Zend Framework path issue

I've been trying to get to grips with zend framework and a bit of php and am having problems with (I think) some sort of path setting. 我一直在尝试使用zend框架和一些php,并且在(我认为)某种路径设置方面遇到了问题。

Basically I'm having some problems with getting a simple page to work. 基本上,我在使用简单的页面时遇到一些问题。

I have a standard directory structure from the zend quickstart sample. 我有一个来自zend quickstart示例的标准目录结构。 It has the structure: 它具有以下结构:

app
->public
->library 

etc. 等等

When I create the following "hello.php" file in the public directory, I get an error from "require-once" 当我在公共目录中创建以下“ hello.php”文件时,出现“ require-once”错误

Warning: require_once(/../application/Zend/Rest/Server.php) [function.require-once]: failed to open stream: No such file or directory in /home/bestpubi/public_html/svc/public/hello.php on line 2 Fatal error: require_once() [function.require]: Failed opening required '/../application/Zend/Rest/Server.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/bestpubi/public_html/svc/public/hello.php on line 2 警告:require_once(/../ application / Zend / Rest / Server.php)[function.require-once]:无法打开流:/ home / bestpubi / public_html / svc / public / hello中没有此类文件或目录。第2行中的php致命错误:require_once()[function.require]:无法打开所需的'/../application/Zend/Rest/Server.php'(include_path ='。:/ usr / lib / php:/ usr /第2行/home/bestpubi/public_html/svc/public/hello.php中的local / lib / php')

My hello.php file looks like this: 我的hello.php文件如下所示:

<?php
require_once '../application/Zend/Rest/Server.php';
/**
* Say Hello
*/
function sayHello()
{
return 'finally';
}
$server = new Zend_Rest_Server();
$server->addFunction('sayHello');
$server->handle();
?>

I could really do with some help as this is driving me a bit mad, and I'm sure it's something silly. 我真的可以提供一些帮助,因为这使我有点生气,而且我敢肯定这很愚蠢。

You are requesting the required library file as follows. 您正在请求所需的库文件,如下所示。

require_once '../application/Zend/Rest/Server.php';

The error message indicates that, there is no such file in the path specified. 错误消息表明,指定的路径中没有此类文件。

Usuallay zend framework contains it 'Zend' library inside /library directory. Usuallay zend框架在/ library目录中包含它的“ Zend”库。 If you have the Zend directory in your downloaded ZendFramework files, copy it to /library directory. 如果下载的ZendFramework文件中包含Zend目录,则将其复制到/ library目录。 So that the Zend directory structure would be as follows 这样Zend目录结构如下

/library/Zend

This is a simple way to get started. 这是上手的简单方法。 Once you are familiar with the environment, try to use include path in your setting. 熟悉环境后,请尝试在设置中使用包含路径。

Try 尝试

$new_include_path = "/home/www/app/library/";
set_include_path ( get_include_path() . PATH_SEPARATOR . $new_include_path); )

to define the include path of your ZF library. 定义ZF库的包含路径。 Put this on the top of your page, before Including any ZF file. 在包括任何ZF文件之前,将其放在页面顶部。

Edit: I assumed you are on linux, if you are on windows, change path accourdingly 编辑:我假设您在linux上,如果您在Windows上,请更改路径

$new_include_path = "c:\\www\\app\\library";

Looking at your website it seems the index.php from /public works fine. 查看您的网站,似乎来自/ public的index.php正常工作。 So I would suggest copy pasting the code that's in there to set paths for zf into hello.php and it should work. 因此,我建议复制粘贴其中的代码以将zf的路径设置为hello.php,它应该可以工作。

First thing is create your files in application folder. 首先是在应用程序文件夹中创建文件。

And If You are using Linux follow the steps, 如果您使用的是Linux,请按照以下步骤操作:

To use Zend library you can create a short cut to zend library from your library. 要使用Zend库,您可以从库中创建一个捷径来zend库。 From terminal go to your 'library' directory run the command 从终端转到“库”目录,运行命令

ln -s 'path to your zend library' ln -s'您的zend库的路径'

It will create a shortcut. 它将创建一个快捷方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM