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 co开发者_开发百科ntroller/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.
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');
}
精彩评论