通过 ZendFramwork 使用任何类/命名空间

发布于 2024-08-07 19:49:19 字数 1309 浏览 3 评论 0原文

编辑:其他问题:

  • 我是否必须在new NAMSPACE_CLASSNAME末尾添加“.php”
  • 我可以访问我的控制器/模型中的任何 Zend 包吗? 示例:
<块引用>

/* 控制器 // 方法 // 内部 */

方法 $client = 新 Zend_Http_Client('http://example.org', 大批( '最大重定向' => 0, '超时' => 30));

您好,

正如我已经问过的如何将第 3 方库添加到 ZendFramework ,我还想问,我的库是否在我的每个控制器、模型、视图等中都可用。 注册命名空间并自动加载其类是否意味着,如果我注册 'MyClassXY_' 就可以使用 'MyClassXY_someMethod'

我的问题的另一部分是关于在我的控制器中使用任何 Zend 内部类/组件/方法。 据我从 CakePHP 了解到,我可以执行 App::import('appIwantToLoad') 或使用 组件 在我的控制器/模型上使用任何 CakePHP 类/组件。 ZendFramework 似乎有点不同: 我听说过“工厂”方法,它使用放入工厂方法的参数数组来实例化例如 Cache Object

如果您仍然不明白我的问题是什么,我尝试给您一个简单的例子:

我坐在我的控制器前面,我想访问 ZendFramework 的 ACL 或 Cache 模块。 我没有设置任何要加载的特定命名空间(只是要加载“Default_”),也没有设置要加载的任何特定资源(FrontController 和所有其他基本 MVC 资源除外)。

现在我可以使用 ($Namespace_Module_AdditionalStuff) $ZendModuleXY = $Zend_Module_AdditionalStuff::constructionMethod 全局访问这个或那个类或方法?

非常感谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

相权↑美人 2024-08-14 19:49:19

如果您为 MyClassXY 库设置自动加载,则可以使用该目录下的任何类。例如:

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

b) 您可以将引导资源存储在 Zend_Registry 中。

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

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

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');
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文