ZendFramwork ile herhangi bir sınıf / namespace kullanımı

1 Cevap php

EDIT: Ek sorular:

  • I new NAMSPACE_CLASSNAME sonunda '. php' eklemek zorunda
  • Can I access any Zend package inside my controller / model, for example:

/ * Kontrol / / Yöntemleri / / içinde bir * /

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

, Selam

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 ve 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.

Hala benim sorunum hakkında ne olduğunu anlamak yoksa, ben size basit bir örnek vermeye çalışalım:

I sit in front of my controller ve I want to access the ACL or Cache module of ZendFramework. I did not set any specific namespace to load (just 'Default_' to load) ve I did not set any specific resource to load (except the FrontController ve 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?

Çok teşekkür ederim.

1 Cevap

Eğer MyClassXY lib için autoloading kurarsanız, o dir altında herhangi bir sınıf kullanabilirsiniz. Örn:

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

b) Zend_Registry daki önyükleyicisini kaynakları saklayabilirsiniz.

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

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