Quote:
Originally Posted by Mark^Bastard
That sounds good. So you have a base dir, and you wrote a function to scan all children dirs recursively and if one matches the name 'models', it's added to the include path?
That definitely works for me.
|
Exactly; in my bootstrap I have the following code (I'm using the modular structure of ZF):
PHP Code:
$includePath = PATH_SEPARATOR . '../library';
// Add model directories to include path
if($dhApp = opendir('../application/modules'))
{
while(($dirApp = readdir($dhApp)) !== false)
{
if(substr($dirApp, 0, 1) != '.' && is_dir('../application/modules/' . $dirApp))
{
if($dhModule = opendir('../application/modules/' . $dirApp))
{
while(($dirModule = readdir($dhModule)) !== false)
{
if($dirModule == 'models' && is_dir('../application/modules/' . $dirApp . '/models'))
{
$includePath .= PATH_SEPARATOR . '../application/modules/' . $dirApp . '/models';
}
}
closedir($dhModule);
}
}
}
closedir($dhApp);
}
// Change include_path to add Zend Frameowrk to the include path
ini_set('include_path', ini_get('include_path') . $includePath);
Quote:
One other thing though, do you have any issue with giving your models names without a suffix or prefix?
Shouldn't there be a better way than just new Nodes() for example? I like how controllers have a naming convention of NameController.
<...snip...>
If we kept things too generic there may be clashes of class names? Particularly amongst different modules if the idea is to make modules able to be placed in different applications.
|
True, I've thought about this too but all Zend related classes have a prefix or suffix anyway. If you like to create a Node controller, you have to name the class NodeController anyway.
The only conflict you might have is that an external lib is using the same classname. But using a suffix of Model isn't a bad idea anyway!