On Thu, Feb 14, 2008 at 9:19 PM, Darby Felton <[EMAIL PROTECTED]> wrote:
> Hi Arthur,
>
> I probably would not call it the "Zend way," but since I'm a Zender,
> I'll share how I have done autoloading model classes using Zend_Loader:
>
> My "bootstrap" class sets up the include_path:
>
> set_include_path($this->getPath('library') . PATH_SEPARATOR .
> get_include_path());
>
> The class also has a _setupAutoloader() method that runs:
>
> require_once 'Zend/Loader.php';
> Zend_Loader::registerAutoload();
>
> This makes subsequent loading of model classes within the include_path a
> piece of cake:
>
> new My_Model_User($identity);
> // loads application/library/My/Model/User.php automatically
>
> Hope this helps!
>
> Best regards,
> Darby
>
>
>
> Arthur M. Kang wrote:
> > What, if any, is the Zend way of autoloading models in the form of
> > modules/modulename/models/modelname.php ? Can the Zend_Loader be used
> > to accomplish this and how?
> >
> > Arthur
>
Hi Arthur,
This is probably the "Ubraa Way" He he
/**
* Scan controllers and models available in the modules directory.
*
* @category Ubraa
* @package Ubraa_Bootstrap
* @copyright Copyright (c) 2001-2007 PHP User-Group
Philippines (http://www.phpugph.com)
* @license http://opensource.org/licenses/osl-3.0.php Open
Software License (OSL 3.0)
* @author Garrizaldy Santos <[EMAIL PROTECTED]>
* @param string
* @param string
* @return array
*/
public function modulesDir($modDir = '', $option = 'controllers')
{
$modules = array();
$filters = array('.', '..', '.svn', '.htaccess', '.htpasswd');
$directories = array_diff(scandir($modDir), $filters);
switch ($option)
{
case 'models':
{
foreach($directories as $module)
{
$modules[] = $modDir . DIRECTORY_SEPARATOR .
$module . DIRECTORY_SEPARATOR . 'models';
}
break;
}
case 'controllers':
{
foreach($directories as $module)
{
$modules[$module] = $modDir .
DIRECTORY_SEPARATOR .
$module . DIRECTORY_SEPARATOR . 'controllers';
}
break;
}
case 'views':
{
break;
}
}
return $modules;
}
If I were to include my Models in the include_path i just need to
array_merge() the array return by this helper function and the array
that contains path to my library and the return of get_include_path().
$this->ubraaLibrary = $this->ubraaRoot . DIRECTORY_SEPARATOR .
'library';
$path = array(
$this->ubraaLibrary,
get_include_path()
);
$models = $this->modulesDir($this->ubraaRoot .
DIRECTORY_SEPARATOR . 'modules', 'models');
$ubraa_path = array_merge($path, $models);
set_include_path(implode(PATH_SEPARATOR, $ubraa_path));
Then just implode() the variable that contains the result of the array_merge().
Garrizaldy R. Santos
Ubraa Developer
PHP User-Group Philippines Inc.
http://www.phpugph.com
[EMAIL PROTECTED]