When trying to include the JPGRAPH library in a Zend Studio project, I got the error
Fatal error: Class 'Graph' not found in C:\Program Files\Zend\Apache2\htdocs\NewStokV4\application\controllers\StatsController.php on line 49
when executing my code.
I tried to follow, unsuccessfully, some tutorials on the net, but none were complete nor clear to me. (I'm new in Zend framework development.)
this is what i get when trying include... or require...
Warning: require_once(vendors/jpgraph-3.5.0b1/src/jpgraph.php) [function.require-once]: failed to open stream: No such file or directory in C:\Program Files\Zend\Apache2\htdocs\NewStokV4\application\controllers\StatsController.php on line 15
Fatal error: require_once() [function.require]: Failed opening required 'vendors/jpgraph-3.5.0b1/src/jpgraph.php' (include_path='C:\Program Files\Zend \Apache2\htdocs\NewStokV4\vendors\Oft_Framework-G1R1C0/vendors/minify-2.1.5/min/lib;C:\Program Files\Zend\Apache2\htdocs\NewStokV4\vendors\Oft_Framework-G1R1C0/vendors/htmlpurifier-4.4.0/library;C:\Program Files\Zend\Apache2\htdocs\NewStokV4\vendors\ZendFramework-1.10.7\library;C:\Program Files\Zend\Apache2\htdocs\NewStokV4\vendors\Oft_Framework-G1R1C0\library;C:\Program Files\Zend\Apache2\htdocs\NewStokV4/library;C:\Program Files\Zend\Apache2\htdocs\NewStokV4\vendors\ZendFramework-1.10.7\extras\library') in C:\Program Files\Zend\Apache2\htdocs\NewStokV4\application\controllers\StatsController.php on line 15
Regarding your comment:
Solution A (a bit dirty)
Put the whole JPGRAPH library inside \library\jpgraph folder an include it inside your controller via:
require_once(APPLICATION_PATH . '/../library/jpgraph/jpgraph.php');
Solution B (better)
Check if jpgrah uses namespaces. if yes you might want try to load it with the build in autoloader function of zend. Put the whole JPGRAPH library inside \library\JPGraph folder.
Usage: just add autoloaderNamespaces[] = "<jpgraph_namespace>" to your application.ini where <jpgraph_namespace> is the namespace of jpgraph.
So assuming the namespace is JPGraph:
application.ini:
[...]
includePaths.library = APPLICATION_PATH "/../library"
[...]
autoloaderNamespaces[] = "JPGraph"
in your controller:
[...]
$JPGraph = new JPGraph();
[...]
Related
I have following directory structure for view helper in my zendframework project
--application
--views
--helpers
--Test.php
and configuration setting in application.ini is
resources.view.helperPath = APPLICATION_PATH "/views/helpers"
and configuration in Bootstrap.php is
$view->setHelperPath(APPLICATION_PATH . "/views/helpers/");
in Test.php file naming convention is
class Zend_View_Helper_Test extends Zend_View_Helper_Abstract {}
and I am using helper function in module wherever I need it.When I run project via browser, application working fine without any error, but when I invoke phpunit for same application via command line I am getting error something like
Fatal error: Uncaught exception 'ErrorException' with message 'include_once(Zend\View\Helper\Test.php): failed to open stream: No such file or directory' in D:\
zend\ZendServer\share\ZendFramework-1.12.11\library\Zend\Loader.php:134
that means it's going to find Test.php file in zend server library view folder.I am not getting why it's working via browser and not working in phpunit via command line.
I got solution. I have replace my configuration setting of application.ini
resources.view.helperPath = APPLICATION_PATH "/views/helpers"
with
resources.view.helperPath.Application_View_Helper = APPLICATION_PATH "/views/helpers/"
and changed naming convention of Test.php with
class Application_View_Helper_Test extends Zend_View_Helper_Abstract {}
now zend loder will try to find view helper in application directory rather than Zend
I'm working on some helpful method in my entity.
private function setApi($api_address,$api_username,$api_password){
$this->api_address = $api_address;
$this->api_username = $api_username;
$this->api_password = $api_password;
$this->api_client = new SoapClient($api_address); // error
}
Warning: require(App/Entity/SoapClient.php): failed to open stream: No such file or directory in /zendboilerplate/library/Doctrine/Common/ClassLoader.php on line 148 Fatal error: require(): Failed opening required 'App/Entity/SoapClient.php' (include_path='/zendboilerplate/application/../library:/zendboilerplate/application/../library/Bisna/Application/Resource:/zendboilerplate/library:.:/usr/share/php:/usr/share/pear') in /zendboilerplate/library/Doctrine/Common/ClassLoader.php on line 148
It seems that zend looks for a class declaration (and it doesn't use included classes in php).
Identical error for each "new Class" declaration.
Using a my own class included in library everything is ok.
(Also tried with #new SoapClient() but no result).
I'm guessing this is namespace related. Try changing the line that is erroring to:
$this->api_client = new \SoapClient($api_address);
that should force it to use the PHP SoapClient instead of the namespace that is presumably declared at the start of the file you're having trouble with.
I'm trying to get the zend framework running, but the include path doesn't like me ;)
The zend directory is here http://mydomain.com/zend/
<?php
set_include_path('/var/www/www.mydomain.com/htdocs/zend/library/');
require_once 'Zend/Gdata/Youtube.php';
require_once 'Zend/Loader.php'; // the Zend dir must be in your include_path
Zend_Loader::loadClass('Zend_Gdata_YouTube');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
?>
And I get this error:
Warning: require_once(Zend/Gdata/Youtube.php) [function.require-once]:
failed to open stream: No such file or directory in
/var/www/www.mydomain.com/htdocs/zend/index.php on line 4
Fatal error: require_once() [function.require]: Failed opening
required 'Zend/Gdata/Youtube.php'
(include_path='/var/www/www.mydomain.com/htdocs/zend/library/') in
/var/www/www.mydomain.com/htdocs/zend/index.php on line 4
I have a smiliar setup on another server where it works, but here has to be something wrong..
I think you want:
require_once 'Zend/Gdata/YouTube.php';
(note the capital T). Your other server where it works is probably using a case-insensitive file system.
I am just starting with Zend and am having an issue wherein browsing http://localhost renders a blank page. I've set httpd.conf documentroot to /var/www/HTML/public and enabled Zend_layout in bootstrap.PHP. My index.phtml is locatrd in the suggested directory per the .ZF manual.
Does IndexComtroller have to specifically call my index.phtml view? What other things should I check?
Thanks Much!
EDIT: I checked httpd.conf and noted mod rewrite is enabled. .htaccess file in /var/www/html/public has ReWrite Engine ON etc. I've not created a VirtualHost entry in httpd.conf. I simply defined DocumentRoot "/var/www/html/public" Is a virtualhost required to run the framework?
EDIT2: I used php -f /var/www/html/public/index.php and received the following
PHP Warning: require_once(Zend/Application.php): failed to open stream: No such
file or directory in /var/www/html/public/index.php on line 18
PHP Fatal Error: require_once(): Failed opening required 'Zend/Application.php'
(include_path=':.:/usr/share/pear:/usr/share/php') in /var/www/html/public/index.php
on line 18
The first thing to do is make sure you have the appropriate error reporting enabled for development. Make sure these are set in your application.ini file
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
Once you've done this, re-test and post back any error messages you receive.
It seems that you did not setup Zend Framework in your include_path - did you copy the Zend-subdirectory of the installation packages libs-folder into /usr/share/php, so that you now have a directory called /usr/share/php/Zend/?
I get the following error messages:
Warning: include_once(Zend\Db.php) [function.include-once]:
failed to open stream: No such file or directory in
C:\EasyPHP3\www\VPZ\Lib\Zend_1.7.7\Loader.php on line 83
Warning: include_once() [function.include]:
Failed opening 'Zend\Db.php' for inclusion (include_path='VPZ/') in
C:\EasyPHP3\www\VPZ\Lib\Zend_1.7.7\Loader.php on line 83
Warning: require_once(Zend/Exception.php)
[function.require-once]: failed to open stream:
No such file or directory in
C:\EasyPHP3\www\VPZ\Lib\Zend_1.7.7\Loader.php on line 87
Fatal error: require_once() [function.require]:
Failed opening required 'Zend/Exception.php' (include_path='VPZ/') in
C:\EasyPHP3\www\VPZ\Lib\Zend_1.7.7\Loader.php on line 87
i want to include ZendXXX\Db.php
how to change it
create a directory (say 'lib'), and put your Zend directory in it. so your directory structure looks like this:
- application
- lib
|- Zend
- wwwroot
|- index.php
now you should add lib to your include path. edit your index.php file:
$includePath = array();
$includePath[] = '.';
$includePath[] = './../application';
$includePath[] = './../lib';
$includePath[] = get_include_path();
$includePath = implode(PATH_SEPARATOR,$includePath);
set_include_path($includePath);
now you have your lib in your include path. you can include all Zend components like this:
include 'Zend/Loader.php';
require_once 'Zend/Db.php';
the best way is too include Zend_Loader first and then use it to load classes. do this:
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Db');
you can also register to autoload classes. just add this line to your code after all those before:
Zend_Loader::registerAutoLoad('Zend_Loader',true);
now you do not need to include files to call classes. just instanciate your classes:
$session = new Zend_Session_Namespace('user');
there is no need to include 'Zend/Session/Namespace.php'.
Use set_include_path(). See PHP.net documentation
Example:
set_include_path(get_include_path() . PATH_SEPARATOR . '/path/to/Zend');
I usually store the framework files under a "library" folder:
application
public_html
library
Zend
Common
etc....
and then in my bootstrap file, or front controller, I add that "library" folder to the include path:
set_include_path(get_include_path() . PATH_SEPARATOR . '../library');
See also:
Choosing Your Application's Directory Layout.
Create the Filesystem Layout.
The reason the other suggestions say anything about doing that, is because it's a bad move - in other words, you're doing it wrong.
You can create a subdirectory and name it Zendxxx, but then you have to add that to your include_path, and change it, whenever you put a newly named version up.
I'd hazard a guess, and say that you don't have a good way to test the website (so you want to lock it to a particular version of ZF), and further, that you aren't using revision control, so you want all the previous versions of code in the site-directory to be able to go back to, if you find a problem when you change the live-running code directly on the server.
project without library And including library from one location
project C:\xampp\htdocs\my\application
library C:\xampp\Zend\library
make changes in index.php
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR,
array(realpath(APPLICATION_PATH.'/../../../Zend/library'),get_include_path(),)));