Last active
December 17, 2015 00:09
-
-
Save ruckuus/5518215 to your computer and use it in GitHub Desktop.
Autoload PHPActiveRecord to work with Silex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Author: Dwi Sasongko S <[email protected]> | |
* See: http://www.phpactiverecord.org/projects/main/wiki/Quick_Start | |
*/ | |
namespace App\Provider; | |
use Silex\Application; | |
use Silex\ServiceProviderInterface; | |
class ActiveRecordServiceProvider implements ServiceProviderInterface | |
{ | |
private $app; | |
public function register(Application $app) | |
{ | |
$this->app = $app; | |
\ActiveRecord\Config::initialize(function ($cfg) use ($app) { | |
$cfg->set_model_directory($app['base_dir'] . '/app/' . $app['name'] . '/Model'); | |
$cfg->set_connections(array( | |
'development' => 'mysql://root@localhost/db_name', | |
)); | |
$cfg->set_default_connection('development'); | |
}); | |
} | |
public function boot(Application $app) | |
{} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"repositories": [ | |
{ | |
"type": "package", | |
"package": { | |
"name": "kla/php-activerecord", | |
"version": "dev-master", | |
"autoload": { | |
"psr-0": { | |
"ActiveRecord": "lib/" | |
}, | |
"files": [ | |
"ActiveRecord.php" | |
] | |
}, | |
"source": { | |
"url": "https://github.com/kla/php-activerecord", | |
"type": "git", | |
"reference": "master" | |
} | |
} | |
} | |
], | |
"require": { | |
"php-activerecord/php-activerecord": "dev-master" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Model; | |
class Problem extends \ActiveRecord\Model | |
{ | |
static $belongs_to = array( | |
array('user') | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Model; | |
class User extends \ActiveRecord\Model | |
{ | |
static $connection = 'development'; | |
static $attr_accessible = array('name', 'surname', 'destiny'); | |
static $alias_attribute = array( | |
'alias_name' => 'name', | |
'alias_surname' => 'surname', | |
'alias_destiny' => 'destiny' | |
); | |
static $has_many = array( | |
array('problem'), | |
array('affair') | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment