Not sure what I'm doing wrong here, all I thought I had to down was change my PHP ini settings to
include_path = ".;c:\Program Files (x86)\WAMP\www\Zend\"
But it's not working.
On my script I simply have:
require_once "Date.php";
But get the errors:
Warning: require_once(Zend/Date/DateObject.php) [function.require-once]: failed to open stream: No such file or directory in C:\Program Files (x86)\WAMP\www\Zend\Date.php on line 25
Fatal error: require_once() [function.require]: Failed opening required 'Zend/Date/DateObject.php' (include_path='.;c:\Program Files (x86)\WAMP\www\Zend\') in C:\Program Files (x86)\WAMP\www\Zend\Date.php on line 25
Any insight in to what I am doing wrong is greatly appreciated.
Thanks.
You should not add the Zend Framework directory to the include path. You should add it's parent folder to the include path.
Thus, include_path = ".;c:\Program Files (x86)\WAMP\www\Zend\" would become include_path = ".;c:\Program Files (x86)\WAMP\www\".
After setting up your include path like this, you should use require_once 'Zend/Date.php' instead of require_once 'Date.php'. This is because there are still a lot of require calls inside the framework itself, each pointing to Zend/<classname>.
Your include path is wrong - you can either define it manually or (better) change your php.ini to add the location of your requred includes...
http://www.geeksengine.com/article/php-include-path.html
edit: these may help you
Trouble setting up php Zend include path
http://devzone.zend.com/article/4683
Everybody here suggests you add the library to your include path. I actually disagree with that. Most hosting providers does not have the ZF on a include path, and does not allow you to add it to one. So why set it up like that on your development environment; only to change it on production?
I suggest you create a library folder in your root; put the ZF in there and add that in your APPLICATION to the include path.
E.g. c:\wamp\www\library\Zend
Then for each application add the library in the index.php (you will just go one more folder up):
set_include_path(implode(PATH_SEPARATOR, array(
realpath(dirname(__FILE__) . '/../../library'),
get_include_path(),
)));
This allows you to easily update your ZF library.
It also allows you to easily copy/svn your projects without including the ZF framework.
Most people have their own style. I agree with most that you must include the library directory and not the Zend directory.
Set include path:
include_path = ".;c:\Program Files (x86)\WAMP\www\"
After:
require_once "Zend/Date.php";
You should not add the Zend/ directory to your include path but either the root of your your library folder:
If your Zend library is in www/
your include path must be: c:\Program Files (x86)\WAMP\www\
However, if ZF is in Zend/library/ it should be:
c:\Program Files (x86)\WAMP\www\Zend\library\
It is because how the file are required.
Zend_Date requires Zend/Date/DateObject from Zend/ so you need to include top level directory.
Note, that you can also use the autoloader to do the work for you if you need other Zf classes and don't want to include/require them all.
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
Will allow you to do $date = new Zend_Date(); without require manually any files (except Loader of course!)
Related
I have searched the forums already, but none of the solutions have seemed to help me.
Basically I have just installed and created a package using composer. I need to autoload the classes, sounds pretty standard.
I followed all the instructions, and have added this line of code to my script:
require_once 'vendor/autoload.php';
The vendor folder is located in the root folder of my server, here:
/root/vendor/autoload.php
So, I added
:/root
To my PHP ini file so that PHP searches in the root folder when looking for includes. I thought that should work but it's not :(
My PHP ini file now looks like this:
.:/usr/lib/php:/usr/local/lib/php:/root
The error message I am getting is this:
[14-Jul-2014 16:46:29 Europe/London] PHP Fatal error: require_once(): Failed opening required 'vendor/autoload.php' (include_path='.:/usr/lib/php:/usr/local/lib/php:/root') in /home/owned/public_html/trythis/ow_plugins/oftokbox/bol/service.php on line 38
Any ideas?
You implicitly state you are using Composer for a project. By doing so you must have a composer.json file somewhere. And Composer will create a vendor folder directly in the folder containing this file.
So if you also have a file index.php in the folder containing the composer.json, to include the autoloader you would use require 'vendor/autoload.php';.
If however you follow some security guidelines and have a dedicated folder containing public files, then the file would for example be called public/index.php, and for this file to reach the autoloader, the relative path would be require '../vendor/autoload.php';.
Composer cannot give a one-instructions-fits-all direction because it depends on which folder structure you have. But including the composer autoloader is just the same task as including any other file with a relative path.
I am using xampp to develop my php application. Few days back I installed pear ti use DB abstraction. After that, I couldn't use include files from parent directory, however I can include from sub-driectories.
Here is what I see when I check my include path
.;E:\xampp\php\PEAR
I tried changed include path using set_include_path to the location where my files are stored, then the application failed to load Pear files.
Any help appreciated.
Easiest way to prepend to the include path stack is...
set_include_path(implode(PATH_SEPARATOR, array(
'path/to/app/includes',
'path/to/any/other/includes',
get_include_path()
)));
If you really want to use set_include_path, you can do it like this:
set_include_path(get_include_path().PATH_SEPARATOR.'path_to_parent');
Use the predefined constant DIRECTORY_SEPARATOR in case your code moves to a server that uses a different directory separator.
Personally if I needed to set the path specially for a particular site, I would try to set the path in the .htaccess file in the site's web root. It provides a more obvious place to look for site-wide configurations like the include_path. Here is the line you would put in the .htaccess file:
php_value include_path ".;E:\xampp\php\PEAR;path_to_parent"
or on a Linux server:
php_value include_path ".:some_path/PEAR:path_to_parent"
I'm writing a tiny school project in php. I needed to display some information in a pdf format and send the file via mail.
When i've copy the PDF folder with the pdf class file from the librairy.here is my folder structure
/
/lib
/Swift
/....
/Zend
/Pdf
Pdf.php
test_file.php
here is the content of test_file.php
require_once 'lib/Zend/Pdf.php';
$pdf = new Zend_Pdf();
$pdf->render();
and it's throwing this
( ! ) Fatal error: require_once() [function.require]: Failed opening required 'Zend/Pdf/Page.php' (include_path='.;C:\xampp\php\PEAR;C:\ZendFramework-1.10.8\bin;') in C:\xampp\htdocs\schoolproject\lib\Zend\Pdf.php on line 27
but i did notice that all classes includes by referring to the top Zend folder, even siblings classes ex :
require_once 'Zend/Pdf/Page.php';
i'm a little confuse about how to deal with that. I'm think about autoload feature or manually correct the require path to suit my project (which will be a pain).
What's the best way to go around it?
THanks for reading this.
Well, you need to configure your include path to the root of the Zend Framework library folder.
set_include_path(implode(PATH_SEPARATOR, array(
'c:\ZendFramework-1.10.8\library',
get_include_path(),
)));
As Zend uses pseudo namespaces, you need to include the toplevel directory library/ and not library/Zend
You may also want to use Autoloader
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();
It avoids you to call require_once() each time you need to 'require' a file to load a Class
You have to register the ZF autoloader. After that you can just use the classes and the autoloader will figure out the rest.
$zf_path = 'PATH/TO/YOUR/LIB/FOLDER';
set_include_path($zf_path.PATH_SEPARATOR.get_include_path());
require_once($zf_path.'/Zend/Loader/Autoloader.php');
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('Zend_');
I am trying to include the Zend framework, but I keep getting this error,
Warning: require_once(Zend/Json.php) [function.require-once]: failed to open stream: No such file or directory in /usr/www/users/eyelogicy/zone.eyelogic.co.za/weskom/form/classes/ZendFramework/Zend/Json/Decoder.php on line 25
here is the PHP code I am using to include the framework,
set_include_path('classes/ZendFramework' . PATH_SEPARATOR . get_include_path());
require_once 'Zend/Json/Decoder.php';
Any ideas?
Thanx in advance!
Try an absolute path for the include path.
Using absolute path is also a good practise advice:
One trivial optimization you can do to increase the speed of class loading is to pay careful attention to your include_path. In particular, you should do four things: use absolute paths (or paths relative to absolute paths), reduce the number of include paths you define, have your Zend Framework include_path as early as possible, and only include the current directory path at the end of your include_path.
I have dumped Zend Framework files in
"home/hotbuzz/public_html/include/zend/"
My hosting : linux
I want to load it in my script. Whenever I load I get this error.
Some info: I asked about my Zend, to hosting guys they said its located in "usr/local/zend"
But I want to use this home/hotbuzz/public_html/include/zend/
I had added these lined in my PHP:
set_include_path(dirname(__FILE__).';'.get_include_path());
require_once 'Zend/Loader.php';
I get this error
Fatal error: require_once() [function.require]: Failed opening required 'Zend/Exception.php' (include_path='/home/hotbuzz/public_html/include;.:/usr/lib/php:/usr/local/lib/php') in /home/hotbuzz/public_html/include/Zend/Loader.php on line 87
I want to set include path in my PHP code and configure it (.htaccess).
As I said in your previous question. Do not use ';' but use PATH_SEPARATOR.
This is a PHP constant that represent the right separator for your system (semi-colon on windows and colon on linux)
set_include_path(dirname(__FILE__).PATH_SEPARATOR.get_include_path());
You were doing it right. You should call set_include_path in first lines of your main script (index.php) and then include/require zend framework files. Remember to rename your Zend Framework containing folder to 'Zend' (uppercase Z) to follow ZF naming conversions, then put your Zend folder in your include directory.
<?php
$newIncludePath = array();
$newIncludePath[] = '.';
$newIncludePath[] = 'include';
$newIncludePath[] = get_include_path();
$newIncludePath = implode(PATH_SEPARATOR, $newIncludePath);
set_include_path($newIncludePath);
// now include path is setup and we can use zend
require_once 'Zend/Loader.php';
Zend_Loader::registerAutoLoad('Zend_Loader', true);
// the rest of the code
?>
If you put your Zend directory in your include path, and not the include directory (that contains the Zend directory), you may not use this:
require_once 'Zend/Loader';
instead you should use:
require_once 'Loader';
which is not a good idea. by using the Zend/* model, you will remember which files are included from Zend Framework and which files are you own. so just add the include directory to your include path.
You may have more success if you use auto_prepend rather than include...
php_value include_path /home/hotbuzz/public_html/include/zend/
php_value auto_prepend_file Zend/Loader.php
What do you get in the apache log on startup and execution with that?
you can attach the below code in the first line of your bootstrap.php:
set_include_path('.' . PATH_SEPARATOR . '../library' . PATH_SEPARATOR . '../application/models/' . PATH_SEPARATOR . get_include_path());