开发者

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 abou开发者_运维问答t 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_');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜