承接 rogerthomas84/ohdm 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rogerthomas84/ohdm

Composer 安装命令:

composer require rogerthomas84/ohdm

包简介

OhDM is a PHP Object Document Mapper (ODM) for MongoDB

README 文档

README

Build Status

View on Packagist

OhDM

OhDM is a an ODM which is a simple PHP library that eases the pain of interacting with MongoDB.

Stability

OhDM is a new project, so some things won't work as expected. It's classified right now as in the early stages, and there is a version 1.0.0 which we're classing as stable.

Saying that, things will be introduced to help enhance the library further but it'll be versioned accordingly.

Help Out

The easiest way to help is by forking and raising a PR. All I ask is that you contribute changes back to this repository.

Changes won't be merged unless you've tested (and written tests) for the changes made. We also strive for high test coverage.

Right now, we're sitting at 99.33% coverage, and we would really like to stay around there.

Quick Start

To get started quickly, first you're going to need to setup the configuration object. It's a singleton.

<?php
Config::init(
    new \MongoClient(
        'mongodb://127.0.0.1',
        array('connect' => false)
    ),
    'pets' // The database name
);

Now you'll need a Collection model. Something like this:

<?php
namespace My\Namespace\Name;

use OhDM\Collection;

class Cats extends Collection
{
    public $name = null;

    public function setName($name)
    {
        $this->name = $name;
    }

    public function getName()
    {
        return $this->name;
    }
}

Introduction to Queries

Create a document

<?php
$record = new Cats();
$record->setName('fuzzy');
$record->save();

Find By ID

The quickest form of find is when you know an objects _id. OhDM exploits this and implements a quick and easy way to locate them.

<?php
$record = Cats::findById(
    new \MongoId('53466f2978f7a8bc5c1ae933')
);
if ($record) {
    // $record is instance of Cats
    echo 'My cats name is: ' . $record->getName();
} else {
    // couldn't find it!
}

Find By Query

OhDM supports finding documents by advanced querying which will also return the item in object form. Spoiler alert: it's as easy as it looks below!

<?php
$command = array(
    'query' => array('name' => 'kitty'),
    'fields' => array(),
    'skip' => 0,
    'limit' => 100,
    'sort' => array(
        'name' => 1
    )
);
$ohDmCursor = Cats::find($command);
while ($ohDmCursor->hasNext()) {
    $thisCat = $ohDmCursor->getNext(); // it's an instance of Cats
}

Delete

Delete can be called on any saved document and it will be removed from the database.

<?php
$record = Cats::findById(
    new \MongoId('53466f2978f7a8bc5c1ae933')
);
$record->delete();

Update

As it's an object, just alter the variables and call save() against it.

<?php
$record = Cats::findById(
    new \MongoId('53466f2978f7a8bc5c1ae933')
);
if ($record) {
    // $record is instance of Cats
    echo 'My cats name was: ' . $record->getName();

    $record->setName('kitty');
    $record->save();

    echo 'My cats name is now: ' . $record->getName();

} else {
    // couldn't find it!
}

统计信息

  • 总下载量: 16
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-04-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固