PHP code example of ruckuus / php-activerecord-service-provider

1. Go to this page and download the library: Download ruckuus/php-activerecord-service-provider library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ruckuus / php-activerecord-service-provider example snippets


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',
));


namespace App\Model;

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

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);
        }
    }
}

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