Zend GData Include Paths - php

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?

Related

Reading album art using php-reader (zend)

I have been trying to use the Zend Id3v2 class (php-reader) to get the album artwork (apic) from an MP3, but it doesn't seem to want to work properly. Is there a different php-reader library available that has been proven to work?
Also, for some reason all of the require_once calls in the function are set to 'Zend/...' and not to an absolute path like require_once $_SERVER['DOCUMENT_ROOT'].'/Zend...', which breaks them because they are trying to get to a subfolder called 'Zend' in the current directory which is a sub directory of Zend. I also can't use Finder & Replace to set it to an absolute path without going through each file manually, as the files in this class are locked. SMH FACEPALM
Zend Framework 1 is written with the assumption that the folder where your Zend is stored is on the include_path.
e.g.
define('LIBRARY_PATH', __DIR__ . '/../library');
set_include_path(implode(PATH_SEPARATOR, array(
realpath(LIBRARY_PATH),
get_include_path(),
)));
This assumes that you're running this code in a sibling folder to library and that your Zend Framework files are in library/Zend

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.
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.

Using Zend_PDF in a stand alone mode, how to set the include of the land class

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_');

Getting Zend Framework to work with WAMP

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 have installed Zend Framework and need to set up include path in PHP?

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());

Categories