Use of any class / namespace with ZendFramwork

徘徊边缘 提交于 2019-12-25 03:27:18

问题


EDIT: Additional questions:

  • do I have to add the '.php' at the end of new NAMSPACE_CLASSNAME
  • Can I access any Zend package inside my controller / model, for example:

/* Controller // Methods // inside a */

method $client = new Zend_Http_Client('http://example.org', array( 'maxredirects' => 0, 'timeout' => 30));

Hi there,

as I already asked How to add 3rd party lib to the ZendFramework, I also wanted to ask, whether my library is available in each of my controllers, models, views etc. Does registering a namespace and autoloading its classes mean, that if I register 'MyClassXY_' enables using 'MyClassXY_someMethod'?

The other part of my question is about using any Zend internal class/component/method within my controller. As I know from CakePHP I can do App::import('appIwantToLoad') or use a component to have any CakePHP class/component available at my controller/model. ZendFramework seems a little bit different: I heard about 'factory' method(s) which instantiates for example a Cache Object using an array of parameters put into the factory method.

If you still do not understand what my problem is about, I try to give you a simple example:

I sit in front of my controller and I want to access the ACL or Cache module of ZendFramework. I did not set any specific namespace to load (just 'Default_' to load) and I did not set any specific resource to load (except the FrontController and all other basic MVC ressources).

Now can I just use ($Namespace_Module_AdditionalStuff) $ZendModuleXY = $Zend_Module_AdditionalStuff::constructionMethod to globaly access this or that class or method?

Thank you very much.


回答1:


If you set up autoloading for your MyClassXY lib, you can use any class under that dir. E.g:

//if there is library/MyClassXY/Foo.php with class MyClassXY_Foo
new MyClassXY_Foo
//is valid

b) You can store your bootstrapped resources in Zend_Registry.

Zend_Registry::set('dbConnection', $resource);

class App_Another_Class
{
    /* */
    $resource = Zend_Registry::get('dbConnection');
}


来源:https://stackoverflow.com/questions/1573523/use-of-any-class-namespace-with-zendframwork

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!