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 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)