Using PHP namespaces in a Zend Framework (v1) application

前端 未结 2 1334
孤独总比滥情好
孤独总比滥情好 2020-12-08 11:59

Is it possible in the current stable version of the Zend Framework (1.11), to work with application classes using PHP namespaces?

Application\\Form\\Abc inst         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-08 12:17

    Actually there is a simple workaround suggested by Dmitry on the ZF issue tracker:

    class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
    {
        protected function _initAutoloader()
        {
            $loader = function($className) {
                $className = str_replace('\\', '_', $className);
                Zend_Loader_Autoloader::autoload($className);
            };
    
            $autoloader = Zend_Loader_Autoloader::getInstance();
            $autoloader->pushAutoloader($loader, 'Application\\');
        }
    }
    

    Works like a charm for me!

提交回复
热议问题