如何将MongoDB与Kohana 3.3一起使用?使用MangoDB

时间:2022-10-13 12:36:08

I'm trying to use MongoDB with Kohana using MangoDB. I've downloaded MangoDB which is a library to use MongoDB with Kohana https://github.com/Wouterrr/MangoDB

我正在尝试使用MangoDB将MongoDB与Kohana一起使用。我已经下载了MangoDB,这是一个将MongoDB与Kohana一起使用的库https://github.com/Wouterrr/MangoDB

I know some of the questions here are very basic, but I need to ask because I couldn't find any documentation for MangoDB.

我知道这里的一些问题非常基础,但我需要问一下,因为我找不到MangoDB的任何文档。

First, I don't know where to copy/paste the downloaded library. Second, can I define the database at modules/database/config/database.php, probably something like:

首先,我不知道在哪里复制/粘贴下载的库。其次,我可以在modules / database / config / database.php中定义数据库,可能是这样的:

...
'default' = array
(
   'type'   => 'mongodb',
   'connection' => array(
      'hostname' => 'no idea what to put here'
      'database' => 'example'
      'username' => 'no idea what to put here'
      'password' => 'no idea what to put here'
      'persistent' => 'no idea what to put here'
   ),
...

Third, what should I change at application/bootstrap.php, should I change anything there? Or what should I do exactly.

第三,我应该在application / bootstrap.php上改变什么,我应该改变什么吗?或者我该怎么办呢。

...
kohana::modules(array(
   'database' => MODPATH.'database',
   'orm' => MODPATH.'orm',
...

I would really appreciate any help or guidance to get started with this.

我真的很感激任何帮助或指导开始这个。

A similar question was asked before here: How can I use MongoDB in Kohana? and the best answer suggested not using MangoDB at all. But I think it is important to use an ORM/Active Record like library because it makes it easier to change the database in the future.

之前有人问过类似的问题:如何在Kohana中使用MongoDB?并且最好的答案建议根本不使用MangoDB。但我认为使用像库这样的ORM / Active Record很重要,因为它可以在将来更容易地更改数据库。

1 个解决方案

#1


0  

It's good to know how Kohana's cascading file system and Kohana modules work. Basically when you have the same folder structure in application, modules and system than application overwrites modules and modules overwrites system. You should only write your own code in application.

很高兴知道Kohana的级联文件系统和Kohana模块是如何工作的。基本上,当您在应用程序中具有相同的文件夹结构时,模块和系统比应用程序覆盖模块和模块覆盖系统。您应该只在应用程序中编写自己的代码。

Put the MonogDB module in a dir called mangodb in the modules directory. So you should have some paths like this: modules/mangodb/config and modules/mangodb/classes.

将MonogDB模块放在modules目录中名为mangodb的目录中。所以你应该有这样的路径:modules / mangodb / config和modules / mangodb / classes。

Do not define anything in modules/database/config/database.php, instead copy and rename this file to application/config/database.php. Because the array key name is "default", you application should now use this file. Of course, change the config parameters to work with your own database.

不要在modules / database / config / database.php中定义任何内容,而是将此文件复制并重命名为application / config / database.php。因为数组键名是“default”,所以应用程序现在应该使用此文件。当然,更改配置参数以使用您自己的数据库。

Don't forget to enable the module in your bootstrap.php, I added the last module mangodb in this piece of code:

不要忘记在bootstrap.php中启用该模块,我在这段代码中添加了最后一个模块mangodb:

Kohana::modules(array(
    'auth'       => MODPATH.'auth',       // Basic authentication
    'cache'      => MODPATH.'cache',      // Caching with multiple backends
    'codebench'  => MODPATH.'codebench',  // Benchmarking tool
    'database'   => MODPATH.'database',   // Database access
    'image'      => MODPATH.'image',      // Image manipulation
    'orm'        => MODPATH.'orm',        // Object Relationship Mapping
    'oauth'      => MODPATH.'oauth',      // OAuth authentication
    'pagination' => MODPATH.'pagination', // Paging of results
    'unittest'   => MODPATH.'unittest',   // Unit testing
    'mangodb'  => MODPATH.'mangodb',  
    ));

#1


0  

It's good to know how Kohana's cascading file system and Kohana modules work. Basically when you have the same folder structure in application, modules and system than application overwrites modules and modules overwrites system. You should only write your own code in application.

很高兴知道Kohana的级联文件系统和Kohana模块是如何工作的。基本上,当您在应用程序中具有相同的文件夹结构时,模块和系统比应用程序覆盖模块和模块覆盖系统。您应该只在应用程序中编写自己的代码。

Put the MonogDB module in a dir called mangodb in the modules directory. So you should have some paths like this: modules/mangodb/config and modules/mangodb/classes.

将MonogDB模块放在modules目录中名为mangodb的目录中。所以你应该有这样的路径:modules / mangodb / config和modules / mangodb / classes。

Do not define anything in modules/database/config/database.php, instead copy and rename this file to application/config/database.php. Because the array key name is "default", you application should now use this file. Of course, change the config parameters to work with your own database.

不要在modules / database / config / database.php中定义任何内容,而是将此文件复制并重命名为application / config / database.php。因为数组键名是“default”,所以应用程序现在应该使用此文件。当然,更改配置参数以使用您自己的数据库。

Don't forget to enable the module in your bootstrap.php, I added the last module mangodb in this piece of code:

不要忘记在bootstrap.php中启用该模块,我在这段代码中添加了最后一个模块mangodb:

Kohana::modules(array(
    'auth'       => MODPATH.'auth',       // Basic authentication
    'cache'      => MODPATH.'cache',      // Caching with multiple backends
    'codebench'  => MODPATH.'codebench',  // Benchmarking tool
    'database'   => MODPATH.'database',   // Database access
    'image'      => MODPATH.'image',      // Image manipulation
    'orm'        => MODPATH.'orm',        // Object Relationship Mapping
    'oauth'      => MODPATH.'oauth',      // OAuth authentication
    'pagination' => MODPATH.'pagination', // Paging of results
    'unittest'   => MODPATH.'unittest',   // Unit testing
    'mangodb'  => MODPATH.'mangodb',  
    ));