drpjdfj618393 2012-05-30 20: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 21: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.

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

报告相同问题?

悬赏问题

  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM