Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #11 (permalink)  
Old 09-04-2008, 08:24 PM
Junior Member
 
Join Date: Sep 2008
Posts: 1
Lightbulb another proposal for model autoloading

hi guys,

here is the way I handle this issue :

1) add the models foldes to include path :

PHP Code:
// add ZF Home and models folders to include_path
$includePath = array(
    
'/opt/ZendFramework/1.6/library/' 
    
'../library' 
    
'../application/common/models/' 
    
'../application/forum/models/' 
    
'../application/admin/models/' 
    
'.' 
    
get_include_path()
);
set_include_path(implode(PATH_SEPARATOR$includePath)); 
2) register an autoload function

a] under windows
PHP Code:
spl_autoload_register(); 
By doing this, spl_autoload() will be automatically registered as autoloader, and will look for {$classname}.php and {$classname}.inc in every directory listed in include path.

b] under GNU/Linux
You may paid attention to the {$classname} instead of {$className}? If yes, you already understood why it is necessary to create a home made autoloader function for Linux : spl_autoload() lowercase the class name when it looks for the source file. So, when there is no problem with Windows (whose filesystem is case insensitive), using this trick under Linux would lead you to break the file naming convention of ZF. To avoid this horrible crime , just add this code somewhere in/from your bootstrap :

PHP Code:
function modelAutoloader($className) {
    require_once 
"$className.php";
}
spl_autoload_register('modelAutoLoader'); 

Last edited by gauthier : 09-05-2008 at 03:30 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 06:42 PM.