All,
I'm trying to load my Zend framework with the following code:
require_once $themePath.'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata', 'D:\My Documents\xampp\htdocs\wordpress\wp-content\themes\theme');
Zend_Loader::loadClass('Zend_Gdata_HttpClient', 'D:\My Documents\xampp\htdocs\wordpress\wp-content\themes\theme');
Zend_Loader::loadClass('Zend_Json', 'D:\My Documents\xampp\htdocs\wordpress\wp-content\themes\theme');
This gets me part of the way there. However, when it tries to load Zend/Gdata/App.php on the next page it says that it can't find it. I figured that it would work but I keep getting the following error:
Warning: require_once(Zend/Gdata/App.php) [function.require-once]: failed to open stream: No such file or directory in D:\My Documents\xampp\htdocs\wordpress\wp-content\themes\theme\Zend\Gdata.php on line 27
Line 27 is then:
require_once 'Zend/Gdata/App.php';
Why won't this work? Thanks for any help in advance!
Try adding the path to where the Zend directory lives to your include path like this:
set_include_path(implode(PATH_SEPARATOR, array(
realpath($themePath),
get_include_path(),
)));
This way, including a file like Zend/Class.php will look in $themePath for the Zend Framework Files. In the current situation, it can't locate the Zend files relative to where they were being included from.
Related
I'm attempting to write a simple script to read from and write to a Google Spreadsheet. I cannot seem to get the correct Zend include paths to work.
I began by using this walkthrough, kindly provided by a fellow developer:
http://www.farinspace.com/saving-form-data-to-google-spreadsheets/
I have been using different permutations of the location of the Zend GData library (downloaded directly from the Zend website), which claims it is supposed to work without the entire framework.
I have tried the following:
1) Zend library folder ZendGdata-1.12.17 right off the web root (since the code provided uses the following convention)
set_include_path(get_include_path() . PATH_SEPARATOR . "$_SERVER[DOCUMENT_ROOT]/ZendGdata-1.8.1/library");
I, of course switched the directory to the correct one, so that I use the following:
set_include_path(get_include_path() . PATH_SEPARATOR . "$_SERVER[DOCUMENT_ROOT]/ZendGdata-1.12.17/library");
This results in this message:
Fatal error: require_once(): Failed opening required 'Zend/Http/Header/HeaderValue.php' (include_path='.:/usr/lib/php5.5:/kunden/homepages/40/USERNAME/htdocs/network/ZendGdata-1.12.17/library') in /homepages/40/USERNAME/htdocs/network/ZendGdata-1.12.17/library/Zend/Http/Client.php on line 45
2) Putting the include path in a php.ini file.
3) Putting the include path in .htaccess
4) Using other set_include_path statements
5) Uploading the Xml folder to the Zend library folder (per another answer)
It seems that I can get the initial loader to load Zend, but in the Google_Spreadsheet.php file it loads several of the classes:
Zend_Loader::loadClass('Zend_Http_Client');
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Spreadsheets');
I've tried putting the Zend GData library into a directory on the same level as the webroot, and still get errors.
I do not have access to SSH or very much past simple control panel functionality (no include path access in php.ini).
Other answers I have looked at:
Zend Gdata include path issue (Loader.php)
Zend Framework include path
ZendGdata framework path set error
AND MANY MORE.
What would happen if you just create script.php in the folder where Zend folder is, so it looks like:
[Zend]
script.php
and inside script.php do this:
<?php
require_once(dirname(__FILE__).'/Zend/Loader/Autoloader.php');
$loader = Zend_Loader_Autoloader::getInstance();
$spreadsheet = new Zend_Gdata_Spreadsheets();
var_dump($spreadsheet);
will it instantiate Zend_Gdata_Spreadsheets object and dump it without errors?
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.
Basically I'm having some problems with getting a simple page to work.
I have a standard directory structure from the zend quickstart sample. 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"
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
My hello.php file looks like this:
<?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. If you have the Zend directory in your downloaded ZendFramework files, copy it to /library directory. So that the Zend directory structure would be as follows
/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. Put this on the top of your page, before Including any ZF file.
Edit:
I assumed you are on linux, if you are on windows, change path accourdingly
$new_include_path = "c:\\www\\app\\library";
Looking at your website it seems the index.php from /public works fine. So I would suggest copy pasting the code that's in there to set paths for zf into hello.php and it should work.
First thing is create your files in application folder.
And If You are using Linux follow the steps,
To use Zend library you can create a short cut to zend library from your library.
From terminal go to your 'library' directory run the command
ln -s 'path to your zend library'
It will create a shortcut.
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!)
I created a site a while ago using zend and smarty. The site is hosted on a virtual machine with centOS. Now I want to create a similar site so I creeated another virtual host, ftp user etc etc on the same machine.
I modified the ini file that contained the paths:
paths.base = /var/www/html/new_path
paths.data = /var/www/html/new_path/data
paths.templates = /var/www/html/new_path/templates
paths.cache = /var/www/html/new_path/data/tmp/cache
paths.public = /var/www/html/new_path/public_html
The porblem is that somehow when I try to access zend/loader.php (I try to load a database object) it is used the loader from the old path (/var/www/html/oldpath/include/zend/loader.php) so naturally I cant access any new objects I create for the new site
(
Warning: include_once(DatabaseObject/New.php) [function.include-once]: failed to open stream: No such file or directory in /var/www/html/old_path/include/Zend/Loader.php on line 146
Warning: include_once() [function.include]: Failed opening 'DatabaseObject/New.php' for inclusion (include_path='.:/var/www/html/old_path/include:/usr/share/pear/') in /var/www/html/old_path/include/Zend/Loader.php on line 146
Fatal error: Class 'DatabaseObject_Chat' not found in /var/www/html/new_path/include/Controllers/ChatController.php on line 8
).
There are no other paths defined anywhere.
Caching is disabled.
It occurs on different computers, browsers, etc so is not a local problem (residual value of some-type).
For any details just ask... I'm stuck.
Zend_Loader looks into include directories defined in your public/index.php. The include path must be set properly to contain both the old directories and the new ones. Note the respective order specified by your include path.
The code in public/index.php should look similar to the following, assuming the use of ZF1:
<?php
...
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../../project_name/path_for_inclusion'),
get_include_path(),
)));
...
The include path can be also adjusted in your .htaccess:
php_value include_path "/var/www/path:/var/www/second_path:/var/www/third"
or you can achieve the effect in general without ZF-specific code:
set_include_path(get_include_path() . PATH_SEPARATOR . $path_to_add);
I am trying to include the Zend_Service_Amazon_S3 file by using
require_once 'Zend/Service/Amazon/S3.php';
I have also included in the include path the directory where the entire Zend library is located, AND the installation is inside Zend Server CE (which includes the Zend Framework by default). However, no matter what I try, I only get the following for my troubles:
Fatal error: require_once() [http://php.net/function.require]: Failed opening required 'Zend/Server/Amazon/S3.php' (include_path='/usr/local/zend/apache2/htdocs:/usr/local/zend/apache2/htdocs/app/:.:/usr/local/zend/share/ZendFramework/library:/usr/local/zend/share/pear:/usr/local/zend/apache2/htdocs/app/vendors') in /usr/local/zend/apache2/htdocs/app/models/item.php on line 3
The Zend/Service/Amazon/S3.php is located under the paths:
/usr/local/zend/share/ZendFramework/library
/usr/local/zend/apache2/htdocs/app/vendors
Your error message says Zend/Server/Amazon/S3.php - Shouldn't it be Zend/Service/Amazon/S3.php?
Could it be the process that is running PHP does not have the required rights to read the file? Don't forget that a directory needs to be executable in order for a process to change to that directory (i.e. see the contents of its subfolders.)