drpjdfj618393 2012-05-30 12:06
浏览 16
已采纳

将RedBean ORM集成到Zend Framework中[关闭]

The manual for RedBean suggests a method for integrating the ORM into Zend Framework.

From the manual:-

open your Zend bootstrap file and add:

   public function run() {
         $loader = Zend_Loader_Autoloader::getInstance()->registerNamespace("RedBean_");
         require_once( APPLICATION_PATH . "/../library/RedBean/redbean.inc.php"); //or rb.php
         R::setup( "mysql:host=localhost;dbname=timereg", "root" );
         Zend_Registry::set("tools", R::$toolbox);
         Zend_Registry::set("db", R::$adapter);
         Zend_Registry::set("redbean", R::$redbean);
         parent::run();
   }

This method does not strike me as being the most efficient as the ORM is being set up in every controller, whether it is needed or not. It is also using Zend_Registry which I don't like.

There are also certain features of RedBean that need integrating properly and that may benefit from configuration via application.ini:-

How can RedBean ORM be integrated into the Zend Framework in a more efficient Zend like manner?

  • 写回答

1条回答 默认 最新

  • douchushao7799 2012-05-30 13:14
    关注

    Depending on what redbean.inc.php does, I don't think you'll be able to improve the efficiency of this too much. The overhead of requiring in a file and setting up a DB connection isn't likely to be significant.

    I'd change the suggested code slightly to:

    protected function _initRedBean()
    {
        $loader = Zend_Loader_Autoloader::getInstance()->registerNamespace("RedBean_");
        require_once APPLICATION_PATH . "/../library/RedBean/redbean.inc.php"; //or rb.php
        R::setup( "mysql:host=localhost;dbname=timereg", "root" );
        Zend_Registry::set("tools", R::$toolbox);
        Zend_Registry::set("db", R::$adapter);
        Zend_Registry::set("redbean", R::$redbean);
    }
    

    to take advantage of the bootstrap's inbuilt resource loading, instead of overriding the run() method (bad practice).

    It might be possible to simply pass in an existing PDO connection if you are also using Zend_Db, to avoid creating a 2nd connection, but that would require some digging around in the code.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部