views:

1056

answers:

2

how do i auto load zend framework classes when i am not using the MVC framework?

A: 

See: http://us.php.net/manual/en/language.oop5.autoload.php

Mark
Zend framework has an autoloader built in that the asker should use.
notJim
+4  A: 

The nice thing about the Zend framework is that it's extremely modular, you can use just about any piece of it you want without adopting the whole thing.

For example, we can use Zend_Loader_Autoloader to set up class auto-loading without having to use Zend_Application

First make sure the Zend library is in your include path:

set_include_path('/path/to/zend/' . PATH_SEPARATOR . get_include_path());

Then require the Autoloader class:

require_once 'Zend/Loader/Autoloader.php';

Then we set up the autoloader:

// instantiate the loader
$loader = Zend_Loader_Autoloader::getInstance();

// specify class namespaces you want to be auto-loaded.
// 'Zend_' and 'ZendX_' are included by default
$loader->registerNamespace('My_App_');

// optional argument if you want the auto-loader to load ALL namespaces
$loader->setFallbackAutoloader(true);

Once the auto-loader is set up (preferably in a bootstrap or something), you can call Zend framework classes (or your own app's classes) without having to require them individually:

$foo = new Zend_Library_Class();
$bar = new My_App_Class();

Read more about it in the documentation

Bryan M.
what abt loading zend framework classes? for now, i am not yet intending to load my own classes
iceangel89
The autoloader will load the Zend classes by default. If the Zend library is in your include path, you could load any class by requiring it: "require_once('Zend/Class/Path'.php'). But with the autoloader, you don't even need to do that.If the auto-loader is working properly, you should be able to reference the Zend classes without any problem:<?php $myview = new Zend_View ?>You can use the autoloader just by itself, no other Zend classes need to be loaded for it to work.
Bryan M.
in other words, i just need to $loader = Zend_Loader_Autoloader::getInstance(); right?
iceangel89
Yes. That's the gist of it.
Bryan M.