在ZendFramwork中使用任何类/名称空间
附加问题:
Additional questions:
- 我是否必须在
new NAMSPACE_CLASSNAME
的末尾添加".php"
- 我可以访问我的控制器/模型内的任何Zend软件包,以用于 示例:
- 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 */
方法$ client =新 Zend_Http_Client(' http://example.org ', 大批( 'maxredirects'=> 0, 'timeout'=> 30));
method $client = new Zend_Http_Client('http://example.org', array( 'maxredirects' => 0, 'timeout' => 30));
你好,
我已经问过如何将第三方库添加到ZendFramework ,我还想问一下,我的库是否在每个controllers
,models
,views
等中都可用.
注册名称空间并自动加载其类是否意味着,如果我注册'MyClassXY_'
会启用'MyClassXY_someMethod'?
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'?
我的问题的另一部分是关于在控制器中使用任何Zend内部类/组件/方法.
如我从CakePHP所知道的,我可以执行App::import('appIwantToLoad')
或使用component
在我的控制器/模型上使用任何CakePHP类/组件.
ZendFramework似乎有点不同:
我听说过'factory'方法,该方法使用工厂方法中放入的参数数组实例化Cache
Object
.
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:
我坐在控制器前面,我想访问ZendFramework的ACL或Cache模块. 我没有设置要加载的任何特定名称空间(只是加载了"Default_"),也没有设置要加载的任何特定资源(FrontController和所有其他基本MVC资源除外).
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).
现在我可以只使用($Namespace_Module_AdditionalStuff
)
$ZendModuleXY = $Zend_Module_AdditionalStuff::constructionMethod
全局访问这个或那个类或方法?
Now can I just use ($Namespace_Module_AdditionalStuff
)
$ZendModuleXY = $Zend_Module_AdditionalStuff::constructionMethod
to globaly access this or that class or method?
非常感谢您.
如果为MyClassXY库设置了自动加载功能,则可以在该目录下使用任何类.例如:
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)您可以将引导资源存储在 Zend_Registry 中.
b) You can store your bootstrapped resources in Zend_Registry.
Zend_Registry::set('dbConnection', $resource);
class App_Another_Class
{
/* */
$resource = Zend_Registry::get('dbConnection');
}