public function initialize() { $slice = new \PHPixie\Slice(); $database = new \PHPixie\Database($slice->arrayData(array('default' => array('driver' => 'pdo', 'connection' => 'sqlite::memory:')))); $this->con = $database->get()->pdo(); $this->initTables(); $this->orm = new \PHPixie\ORM($database, $slice->arrayData(array('models' => array('author' => array('table' => 'author'), 'book' => array('table' => 'book')), 'relationships' => array(array('type' => 'oneToMany', 'owner' => 'author', 'items' => 'book', 'itemsOptions' => array('ownerKey' => 'author_id')))))); }
<?php require_once 'vendor/autoload.php'; $slice = new \PHPixie\Slice(); $database = new \PHPixie\Database($slice->arrayData(array('default' => array('driver' => 'pdo', 'connection' => 'sqlite::memory:')))); //Create tables $connection = $database->get('default'); $connection->execute(' CREATE TABLE fairies ( id INTEGER PRIMARY KEY, name VARCHAR(255) ) '); //Create wrapper classes class FairyEntity extends \PHPixie\ORM\Wrappers\Type\Database\Entity { public function greet() { return "Hello, my name is {$this->name}"; } } //Create wrapper builder class Wrappers extends \PHPixie\ORM\Wrappers\Implementation { //Tell which models have wrapped entities public function databaseEntities() { return array('fairy'); } public function fairyEntity($entity) {
public function getConnection() { if (!$this->connection) { $slice = new \PHPixie\Slice(); $db_config = $this->config()->get('database'); $dsn = sprintf('mysql:host=%s:%d;dbname=%s', $db_config['host'], $db_config['port'], $db_config['name']); $database = new \PHPixie\Database($slice->arrayData(array('default' => array('driver' => 'pdo', 'connection' => $dsn, 'user' => $db_config['user'], 'password' => $db_config['password'])))); $this->connection = $database->get(); } return $this->connection; }