1

我正在尝试为 laravel 版本 3.2.14 实现 mongor 包

我已按照mongor 主页上的文档中提到的所有步骤进行操作

主页中没有关于其使用的文档,但偶然我得到了以下链接:捆绑完整示例

尽管遵循了这一点,但我无法理解为什么我的代码不起作用。

奇怪的是我没有收到任何错误。

我的代码如下

数据库.php

'mongor' => array(
        'hostname'   => '127.0.0.1',
        'connect'    => true,
        'timeout'    => '',
        'replicaSet' => '',
        'db'         => 'census',
        'username'   => 'root',
        'password'   => '',
        ),

user.php(模型)

class User extends Mongor\Model{

    public static $timestamps = true;

    public function __construct($connection = NULL)
    {
        parent::__construct($connection);
        static::$collection = 'user';
    }


}

user.php(控制器)

public function get_index()
    {           
        //return View::make('user.index');
        $users = User::first();
        dd($users);

    }

当我执行这个 url 时,我得到了以下数据:

object(User)#28 (14) {
  ["connection"]=>
  object(Mongor\MongoDB)#29 (4) {
    ["_name":protected]=>
    NULL
    ["_connected":protected]=>
    bool(true)
    ["_connection":protected]=>
    object(Mongo)#30 (4) {
      ["connected"]=>
      bool(true)
      ["status"]=>
      NULL
      ["server":protected]=>
      string(19) "mongodb://localhost"
      ["persistent":protected]=>
      NULL
    }
    ["_db":protected]=>
    object(MongoDB)#31 (2) {
      ["w"]=>
      int(1)
      ["wtimeout"]=>
      int(10000)
    }
  }
  ["exists"]=>
  bool(false)
  ["attributes"]=>
  NULL
  ["dirty"]=>
  array(0) {
  }
  ["ignore"]=>
  array(0) {
  }
  ["includes"]=>
  array(0) {
  }
  ["relating"]=>
  NULL
  ["relating_key"]=>
  NULL
  ["relating_table"]=>
  NULL
  ["_limit"]=>
  NULL
  ["_skip"]=>
  NULL
  ["_where"]=>
  array(0) {
  }
  ["_sort"]=>
  array(0) {
  }
  ["_count":protected]=>
  NULL
}

而当我在 mongo shell 中执行命令 db.user.find() 时,我得到了所有相关的结果。

4

0 回答 0