承接 mawelous/yamop-laravel 相关项目开发

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

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

mawelous/yamop-laravel

Composer 安装命令:

composer require mawelous/yamop-laravel

包简介

Yet another MongoDB ODM for PHP as Laravel Component. Nothing unnecessary, with easy joins.

README 文档

README

Yet another MongoDB ODM for PHP as Laravel Component

What's that?

This is yet another, open source, and very simple MongoDB ODM for Laravel 4. It works like the standard MongoDB PHP extension interface but returns objects instead of arrays (as ODM). Queries stay the same. One of its coolest features are joins which allow you to query for related objects. This version for Laravel is based on Yamop which can be included into any PHP project. In addition to the standard features it supports Laravel based authentication.

Requirements

  • PHP 5.3+
  • PHP MongoDB Extension
  • Laravel 4

Installation

You can simply download it here or use Composer.

In the require key inside the composer.json file add the following

    "mawelous/yamop-laravel": "dev-master"

Save it and run the Composer update command

$ composer update

After this is done, add mongo in your database configuration:

    'mongo' => array(
        'host'     => 'host',
        'port'     => 37847,
        'database' => 'db',
        'user'     => 'user',
        'password' => 'pass'
    ),

Now we need to let Laravel know about this new service provider. To do so add under providers in the config\app.php file the following:

    ...
    'Illuminate\View\ViewServiceProvider',
    'Illuminate\Workbench\WorkbenchServiceProvider',
    ...
    'Mawelous\YamopLaravel\YamopLaravelServiceProvider',

Aliases to the Yamop classes are useful. Add them in the aliases array in the config\app.php file:

    ...
    'Validator'       => 'Illuminate\Support\Facades\Validator',
    'View'            => 'Illuminate\Support\Facades\View',
    ...
    'Mapper'          => 'Mawelous\YamopLaravel\Mapper',
    'Model'           => 'Mawelous\YamopLaravel\Model',

To use Yamop you now just need to extend the Yamop alias Model from within any of your new or existing models:

    class Article extends Model
    {
        protected static $_collectionName = 'articles';
    }

That's it!

Usage

For usage examples and further explanation take a look at the Yamop Documentation. In this release for Laravel you can also use aliases for Mapper and Model which were registered during installation. See the following pagination example.

Pagination

Yamop for Laravel supports pagination out of the box. It implements the _createPaginator method and extends getPaginator, with this you only need to pass the items per page into the method. The second parameter which is the current page number, and the third which is the page parameter name are both optional.

    User::getMapper()
        ->find( 'status' => [ '$ne' => User::STATUS_DELETED ] ) )
        ->sort( [ $field => $direction ] )
        ->getPaginator( $perPage );

    //or
    User::getMapper()
        ->find()
        ->getPaginator( $perPage, $currentPage, 'commentsPage' );

Authentication

Laravel's package of Yamop supports native like authentication. You must first extend your User Model with Yamop's Mawelous\YampoLaravel\User

    class User extends Mawelous\YamopLaravel\User
    {
        protected static $_collectionName = 'users';    
    }

In auth\config.php change the driver to yamop.

    ...
    'driver' => 'yamop',
    ...

Now you can implement it as standard authentication:

    class AuthController extends BaseController {
    
        public function getLogin()
        {
            return View::make( 'auth.login' );
        }
        
        public function postLogin()
        {
            if( Auth::attempt( [ 'nickname' => Input::get( 'nickname' ), 'password' => input::get( 'password' ) ] ) )
            {
                return Redirect::intended( 'dashboard' );
            } else {
                return Redirect::to( '/login' )->with( 'login_failed', true );
            }       
        }
    }

Issues

Any issues or questions please report here

License

Yamop is free software distributed under the terms of the MIT license

统计信息

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

GitHub 信息

  • Stars: 8
  • Watchers: 7
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-06-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固