开发者

Autoload .obj.php files in Zend?

I am using a cus开发者_如何转开发tom scheme in naming my files. Any pointers on how to autoload them with Zend's autoloader?

Thanks!


You can write your own autoloader class and register it with the ZF autoloader. There is a brief bit about this in the manual: http://framework.zend.com/manual/en/zend.loader.autoloader.html#zend.loader.autoloader.interface

Basically it's just a class defining one method which takes the class name as the parameter. So for you it would be something like:

class My_Autoloader implements Zend_Loader_Autoloader_Interface
{
    public function autoload($class)
    {
        $filename = $class.'.obj.php';
        require $filename;
    }
}

the above assumes the classes are on the include path, if not, just stick the full path in front of $filename. Add any other mapping/checking you need in here and then register it as per the example in the manual. Normally you would do this in your bootstrap.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜