View Single Post
  #4 (permalink)  
Old 04-15-2008, 11:58 AM
Piro's Avatar
Piro Piro is offline
Junior Member
 
Join Date: Apr 2008
Location: Holland
Posts: 8
Default

Quote:
Originally Posted by Mark^Bastard View Post
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($dirApp01) != '.' && 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!
Reply With Quote