Trouble setting up php Zend include path

2019-06-26 07:02发布

I am trying to set up a PHP path to my Zend Framework. I am very confused on how to do this. My Zend Framework is located at the following location on my server:

amazon/ZendFramework-1.10.3-minimal

I am going to be creating a couple of php files in the amazon/ directory that will require the Zend Framework. My include path is:

include("ZendFramework-1.10.3-minimal/library/Zend/Service/Amazon.php");

However inside of Amazon.php is the line

require_once 'Zend/Rest/Client.php';

...and then Client.php has more dependencies set up like that, and so on.

How can I set up my include path so that Amazon.php and Client.php (and so on) can correctly reference the location of the Zend Framework?

Thanks

1条回答
狗以群分
2楼-- · 2019-06-26 07:16

You will have to set your include path using set_include_path() in your boostrap file if you are using any. (need to check the ZF layout for details if you are using the ZF).

The Loading of the classes will be handled by the Zend Loader when you include the library/Zend/Loader.php file and calling the function that will enable the automatic loading of classes that reside in your library/Zend folder.

When you set the include path to your library, include the library/Zend/Loader.php and call Zend_Loader::registerAutoLoad() I believe will be able to work without problems.

short example in a file called bootstrap.php

set_include_path('ZendFramework-1.10.3-minimal/library/'.get_include_path());
require_once('Zend/Loader.php');
Zend_Loader::registerAutoload();
查看更多
登录 后发表回答