ruckuus/php-activerecord-service-provider 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

ruckuus/php-activerecord-service-provider

Composer 安装命令:

composer require ruckuus/php-activerecord-service-provider

包简介

A PHPActiveRecord Service Provider for Silex

README 文档

README

A PHP ActiveRecord ServiceProvider for Silex.

History

I was about to use [Available ActiveRecord Extension] (https://github.com/RafalFilipek/ActiveRecordExtension/blob/master/ActiveRecordExtension.php), but then I realised that registerNamespace() is deprecated in later version of Silex. This work is experimental, it has a minimum functionality to "work".

Fetch

The recommended way to install ActiveRecordServiceProvider is through composer.

Just create a composer.json file for your project:

{
    "require": {
        "ruckuus/php-activerecord-service-provider": "dev-master",
        "silex/silex": "1.0.*@dev"
    }
}

Parameters

  • ar.model_dir - Path to where model folder is located ( without trailing slash )
  • ar.connections - Array of connections (name => connection). Connections examples:
    • mysql://username:password@localhost/database_name
    • pgsql://username:password@localhost/development
    • sqlite://my_database.db
    • oci://username:passsword@localhost/xe
  • ar.default_connection - default models connection.

Register

use Silex\Application;
use Ruckuus\Silex\ActiveRecordServiceProvider;

$app = new Application();

$app->register(new ActiveRecordServiceProvider(), array(
    'ar.model_dir' => __DIR__ . '/App/Model',
    'ar.connections' =>  array ('development' => 'mysql://root@localhost/database_name'),
    'ar.default_connection' => 'development',
));

Usage

Create your model in __DIR__ . '/app/Model'. Eg.

namespace App\Model;

class User extends \ActiveRecord\Model {
    static $has_many = array (
        array('problem'),
        array('luck')
    )
}

In your application:

use App\Model\User;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;

class UserProvider implements UserProviderInterface
{
    public function loadUserByUsername($username)
    {
        $user = User::find_by_username(strtolower($username));
        
        if ($user->dirty_attributes()) {
            throw new UnsupportedUserException(sprintf('Bad credentials for "%s"'), $username);
        }
    }
}

For more informations check the website of PHP ActiveRecord. Its wiki.

统计信息

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

GitHub 信息

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

其他信息

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