JREAM
JREAM

Reputation: 5931

How to load class in Zend

Can you tell me what I'm doing wrong with my ZF loader? I placed my ZF libraries inside library/Zend/*

In my index.php file I keep getting this error:

*Warning: require_once(Zend/Gdata/Media.php): failed to open stream: No such file or 
 directory in C:\workspace\testing\library\Zend\Gdata\YouTube.php on line 27

index.php:

require_once 'library/Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_YouTube', array('library/', 'library/Zend/', 'library/Zend/Gdata'));

Upvotes: 1

Views: 3177

Answers (1)

mschr
mschr

Reputation: 8641

I believe the following should work if your files are structured as such

./  (  == c:\workspace\testing\ )
./index.php
./library/
./library/Zend/
./library/Zend/GData/
./library/Zend/GData/YouTube.php
./library/Zend/GData/YouTube/...

index.php

// We need 'Zend' folder to be 'level 1' child folder of a include_path directive
ini_set('include_path', 
    ini_get('include_path') . 
    PATH_SEPARATOR . 
    dirname(__FILE__). DIRECTORY_SEPARATOR. 'library');

// Option 1
require_once 'Zend/Loader/Autoloader.php';
$gdata = new Zend_GData_Youtube();

// Option 2
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_YouTube');
$gdata = new Zend_Gdata_Youtube();

// Option 3 (with no include_path set)
require_once 'Zend/Loader.php';
$dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'library';
// backwards, recursively repeat loading classes which are dependencies of Gdata module
// foreach ( requestedModule::depends as $loadme )                        // PS: bogus code
//   loadClass($loadme, $dir)
Zend_Loader::loadClass('Zend_Gdata_Media', $dir);
Zend_Loader::loadClass('Zend_Gdata_YouTube', $dir);
$gdata = new Zend_Gdata_Youtube();

Upvotes: 1

Related Questions