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.
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 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 trying to run the PEAR XMLRPC inside a plugin function to do some validation. It is all working fine in a standalone app that in a folder on my server, but as soon as I put all the files into my plugin folder, the:
require_once 'XML/RPC2/Client.php';
doesn't work. The Client.php file return an error:
Warning: require_once(XML/RPC2/Exception.php) [<a href='function.require-once'>function.require-once</a>]: failed to open stream:
So i assume it has to do with relative vs non-relative files, but I can't seem to figure out why it works outside of wordpress just fine.
If I start changing all the
require_once 'XML/RPC2...
to be the absolute path on the server the errors start going away, but I feel like I shouldn't have to change the source of PEAR and XMLRPC to do what i need. Any Suggestions?
You could update the PHP include path:
set_include_path(get_include_path() . PATH_SEPARATOR . $pathToPearLibs);
require_once($pathToPearLibs . 'XML/RPC2/Client.php');
This will give PHP one more (correct) place to look after it attempts to load from the wrong place.
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.
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!)