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')))))); }
public function setUp() { $slice = new \PHPixie\Slice(); $filesystem = new \PHPixie\Filesystem(); $locatorConfig = $slice->arrayData(array('directory' => 'assets/layout')); $templateConfig = $slice->arrayData(array()); $root = $filesystem->root(dirname(dirname(dirname(__DIR__)))); $locator = $filesystem->buildlocator($locatorConfig, $root); $template = new \PHPixie\Template($slice, $locator, $templateConfig); $this->toolbar = new \Meling\Toolbar($template); }
public function setUp() { $slice = new \PHPixie\Slice(); $filesystem = new \PHPixie\Filesystem(); $locatorConfig = $slice->arrayData(array('directory' => '/layout/')); $templateConfig = $slice->arrayData(array()); $root = $filesystem->root(__DIR__); $locator = $filesystem->buildlocator($locatorConfig, $root); $template = new \PHPixie\Template($slice, $locator, $templateConfig); $builder = new \Meling\Toolbar\Builder($template); $this->buttons = new \Meling\Toolbar\Buttons($builder); }
<?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; }
<?php require_once 'vendor/autoload.php'; //Required libraries $slice = new \PHPixie\Slice(); $filesystem = new \PHPixie\Filesystem(); //Configuration $locatorConfig = $slice->arrayData(array('directory' => '/templates/')); $templateConfig = $slice->arrayData(array()); //Build dependencies $root = $filesystem->root(__DIR__); $locator = $filesystem->buildlocator($locatorConfig, $root); //And the Template library itself $template = new \PHPixie\Template($slice, $locator, $templateConfig); echo $template->render('fairy', array('name' => 'Stella')); $fairy = $template->get('fairy'); $fairy->name = 'Blum'; echo $fairy->render();
<?php require_once 'vendor/autoload.php'; $slice = new \PHPixie\Slice(); $database = new \PHPixie\Database($slice->arrayData(array('default' => array('driver' => 'pdo', 'connection' => 'sqlite::memory:')))); $orm = new \PHPixie\ORM($database, $slice->arrayData(array('relationships' => array(array('type' => 'oneToMany', 'owner' => 'fairy', 'items' => 'flower'))))); //Create tables $connection = $database->get('default'); $connection->execute(' CREATE TABLE fairies ( id INTEGER PRIMARY KEY, name VARCHAR(255) ) '); $connection->execute(' CREATE TABLE flowers ( id INTEGER PRIMARY KEY, name VARCHAR(255), fairyId INTEGER ) '); //There are no Model classes anymore //They have been split into Repositories, Entities and Queries //This helps to avoid confusion, reach better separation of concerns and ponies and kittens /* We all hated when someone was using entities as queries: $fairy->name = 'Trixie'; $fairy->save(); $fairy->where('name', 'Stella')->find(); */ $fairyRepository = $orm->repository('fairy');