• <legend id='PCTY5'><style id='PCTY5'><dir id='PCTY5'><q id='PCTY5'></q></dir></style></legend>
    1. <i id='PCTY5'><tr id='PCTY5'><dt id='PCTY5'><q id='PCTY5'><span id='PCTY5'><b id='PCTY5'><form id='PCTY5'><ins id='PCTY5'></ins><ul id='PCTY5'></ul><sub id='PCTY5'></sub></form><legend id='PCTY5'></legend><bdo id='PCTY5'><pre id='PCTY5'><center id='PCTY5'></center></pre></bdo></b><th id='PCTY5'></th></span></q></dt></tr></i><div id='PCTY5'><tfoot id='PCTY5'></tfoot><dl id='PCTY5'><fieldset id='PCTY5'></fieldset></dl></div>
    2. <tfoot id='PCTY5'></tfoot>

      <small id='PCTY5'></small><noframes id='PCTY5'>

        • <bdo id='PCTY5'></bdo><ul id='PCTY5'></ul>

        Zend Framework中如何实现服务层?

        时间:2023-10-03

        <small id='g0Gx8'></small><noframes id='g0Gx8'>

        <i id='g0Gx8'><tr id='g0Gx8'><dt id='g0Gx8'><q id='g0Gx8'><span id='g0Gx8'><b id='g0Gx8'><form id='g0Gx8'><ins id='g0Gx8'></ins><ul id='g0Gx8'></ul><sub id='g0Gx8'></sub></form><legend id='g0Gx8'></legend><bdo id='g0Gx8'><pre id='g0Gx8'><center id='g0Gx8'></center></pre></bdo></b><th id='g0Gx8'></th></span></q></dt></tr></i><div id='g0Gx8'><tfoot id='g0Gx8'></tfoot><dl id='g0Gx8'><fieldset id='g0Gx8'></fieldset></dl></div>
          <tbody id='g0Gx8'></tbody>

          <bdo id='g0Gx8'></bdo><ul id='g0Gx8'></ul>

              1. <tfoot id='g0Gx8'></tfoot><legend id='g0Gx8'><style id='g0Gx8'><dir id='g0Gx8'><q id='g0Gx8'></q></dir></style></legend>

                  本文介绍了Zend Framework中如何实现服务层?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在寻找一些好的资源来学习如何在 Zend Framework 中实现内部服务层.这是个有趣的帖子Bookie Link,但没有具体的代码示例.

                  • 在哪里放置服务类 (/application/modules/modulename/services/?);
                  • 如何自动加载它们(自定义自动加载器?)
                  • 最常见的服务(用户、身份验证、购物车、缓存、提要?)
                  • 示例实现(任何 github 存储库?)
                  • 好的做法?

                  解决方案

                  我认为这个问题的答案取决于您的需求、您的时间限制以及您的软件开发的整体方法/风格.

                  我最近 (A) 决定在一个小型但复杂的 Web 应用程序上使用 Zend Framework,该应用程序的期限非常紧迫,并且 (B) 花了大量时间研究 ORM 解决方案和不同的 ZF 应用程序结构.我得出的结论是,没有一刀切的解决方案,您应该尽情发挥创意并构建一个满意的应用程序结构.>

                  如果时间紧迫且应用程序不是太大,那么您可以创建名称类似于 Application_Model_BlahService 的类并将它们存储在 application/models目录,默认情况下它们会被自动加载器选取(假设自动加载器已正确引导).

                  但是,如果您的应用程序较大,或者由于某些其他原因,您想将类拆分到更多目录中,则可以在应用程序目录下创建自己的子目录,并使用类似于下面的代码(可能会存在)在您的 application/Bootstrap.php) 中将这些类添加到自动加载器:

                  受保护的函数 _initResourceLoader(){$this->_resourceLoader->addResourceType('service', 'services', 'Service');$this->_resourceLoader->addResourceType('serviceplugin', 'services/plugins', 'Service_Plugin');}

                  然后您可以创建诸如 Application_Service_Invoice 之类的类,它们将驻留在 application/services/Invoice.phpApplication_Service_Plugin_TaxPlugin 中,它们将驻留在application/services/plugins/TaxPlugin.php.(注意:上面的代码假设您使用的是 Zend_Application).

                  理论上,您可以随心所欲地将模型类与服务类与数据访问类等分开.但同样,这取决于您喜欢的开发风格、应用程序的大小团队,在某种程度上,你的持久层对你有什么要求.

                  最后一件事:查看 Zend_Application_Module_Autoloader 中默认添加到自动加载器的资源列表.(我应该在这个答案中提到我指的是 ZF 1.8+ 吗?)

                  I'm looking for some good resources to learn how to implement internal service layer in Zend Framework. This is interesting post Bookie Link, but with no concrete code samples.

                  • Where to put service classes (/application/modules/modulename/services/?);
                  • How to autoload them (custom autoloader?)
                  • Most common services (user, authentication, cart, cache, feed?)
                  • Sample implementations (any github repos?)
                  • Good practices?

                  解决方案

                  I think the answer to this question depends on your needs, your time constraints and your overall approach to/style of software development.

                  I have recently (A) made the decision to use Zend Framework on a small but complex web application that has a very tight deadline and (B) have spent a LOT of time investigating ORM solutions and different ZF application structures in general. The conclusion I have come to is that there isn't a one-size-fits-all solution and that you should feel free to get creative and build an application structure that you are happy with.

                  If you have tight time constraints and the application isn't too large, then you could just create classes with names like Application_Model_BlahService and store them in the application/models directory and they will get picked up by default by the autoloader (assuming the autoloader has been bootstrapped correctly).

                  But if your application is larger or if, for some other reason, you want to split classes out into more directories, you could create your own sub-directories under the application directory and use something like the code below (which would exist in your application/Bootstrap.php) to add those classes to the autoloader:

                  protected function _initResourceLoader()
                  {
                      $this->_resourceLoader->addResourceType( 'service', 'services', 'Service' );
                      $this->_resourceLoader->addResourceType( 'serviceplugin', 'services/plugins', 'Service_Plugin' );
                  }
                  

                  You can then create classes like Application_Service_Invoice, which would reside in application/services/Invoice.php and Application_Service_Plugin_TaxPlugin, which would reside in application/services/plugins/TaxPlugin.php. (Note: the code above assumes you are using Zend_Application).

                  You could, in theory, take this as far as you like and separate model classes from service classes from data access classes, etc etc etc. But again, it depends on the style of development that you prefer, the size of the team and, to some degree, what requirements your persistence layer imposes on you.

                  One last quick thing: have a look in Zend_Application_Module_Autoloader for a list of resources that are added to the autoloader by default. (Should I have mentioned that I'm referring to ZF 1.8+ in this answer?)

                  这篇关于Zend Framework中如何实现服务层?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何使用 Zend_Db 添加多于一行? 下一篇:PHPUnit 输出导致 Zend_Session 异常

                  相关文章

                  最新文章

                    <bdo id='raamy'></bdo><ul id='raamy'></ul>
                1. <i id='raamy'><tr id='raamy'><dt id='raamy'><q id='raamy'><span id='raamy'><b id='raamy'><form id='raamy'><ins id='raamy'></ins><ul id='raamy'></ul><sub id='raamy'></sub></form><legend id='raamy'></legend><bdo id='raamy'><pre id='raamy'><center id='raamy'></center></pre></bdo></b><th id='raamy'></th></span></q></dt></tr></i><div id='raamy'><tfoot id='raamy'></tfoot><dl id='raamy'><fieldset id='raamy'></fieldset></dl></div>

                  <small id='raamy'></small><noframes id='raamy'>

                2. <tfoot id='raamy'></tfoot>

                    <legend id='raamy'><style id='raamy'><dir id='raamy'><q id='raamy'></q></dir></style></legend>