views:

49

answers:

4

I have several separate websites that live in separate directories. For includes that they have in common, I have it living in the root directory where the rest of them live.

user@hostname:/var/www$ ls
website_1 website_2 website_3 common_files 

I want to include a Zend package, so I have my include path

ini_set("include_path", get_include_path() . ":/var/www/common_files/Zend");
require_once("Mail.php");

Mail.php loads okay, but then somewhere in there is this line

require_once 'Zend/Mail/Transport/Abstract.php';

which gives this error

Warning: require_once(Zend/Mail/Transport/Abstract.php): failed to open stream: No such file or directory in var/www/common_files/Zend/Mail.php on line 26

So php doesn't recursively descend into the directory structure of the include paths. Do I have to move Zend into each website direcory, spell out the path to every include, or what?


BTW Abstract does exist:

user@host:/var/www/common_files/Zend$ tree -d 
...
`-- Mail/Transport
    |-- Mail/Transport/Abstract.php
    |-- Mail/Transport/Exception.php
    |-- Mail/Transport/Sendmail.php
    `-- Mail/Transport/Smtp.php

9 directories, 32 files
+1  A: 

Stupid answer: Does Abstract.php exist?

require_once 'Mail/Transport/Abstract.php';

Try this, because Mail.php iz already in Zend folder, I guess it looks for /Zend/Zend/.../Abstract.php

Webarto
Good thought :) It does.
I would include that, but there are other includes, so is there a way around writing an include for each file? Why can't the `require_once` that the Zend folks wrote into their files just work?
+7  A: 

EDIT: You want to change your include_path to include /var/www/common_files

What, if anything, is still broken after you do this?

Brandon Horsley
Where do I include it the second time? The `require_once` line you reference is in Zend's Mail.php library file, not in my file. They intended it to work this way.
If the require_once is outside of your control, then try changing the ini_path to just `/var/www/common_files` and alter your `Mail.php` to be `Zend/Mail.php`
Brandon Horsley
Exactly. ZF expects the top-level Zend/ directory to be inside a directory in the include_path. OP wants `/var/www/common_files` in his include path.
timdev
+1  A: 

It looks like Zendis the working directory here, so your statement is looking for /Zend/Zend/Mail/Transport/Abstract.php. Try just cutting off Zend from the statement and it should work fine.

Andrew
IT works, but I don't get it. If the include_path is just `/var/www/common_files` and I `require_once('Mail.php')`, how does it know to put the `Zend` in the middle? The path to `Mail.php` is `/var/www/common_files/Zend/Mail.php`
Oh, I get it. It *does* recursively search the directory! :P
If Mail.php exists in the same directory as the php file including it, and `.` is in the include_path, then it will be found without searching through the rest of your include_path.
Brandon Horsley
It doesn't exist in the same directory. It exists one dir above, in a common directory, so I don't have to include it redundantly in five different projects.
A: 

you need to set your include path to the path where the Zend folder is. then you include the files like so

require_once 'Zend/Mail.php'
Raoul Duke