1. Go to this page and download the library: Download csrdelft/orm 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/ */
csrdelft / orm example snippets
CsrDelft\Orm\Configuration::load([
'cache_path' => '/path/to/data/dir/cache.socket', // Host or unix socket
'cache_port' => 11211, // Optional if cache_path is a host
'db' => [
'host' => 'localhost',
'db' => 'myDatabase',
'user' => 'myUser',
'pass' => 'myPass'
]
]);
$car = new Car();
Database::transaction(function () use ($car) {
CarModel::instance()->create($car);
CarWheelModel::instance()->create($car->getWheels());
});
$container = $kernel->getContainer();
DependencyManager::setContainer($container);
$container->set(OrmMemcache::class, new OrmMemcache($cachePath));
$container->set(Database::class, new Database($pdo));
$container->set(DatabaseAdmin::class, new DatabaseAdmin($pdo));
class OwnerModel extends PersistenceModel {
const ORM = 'Owner';
/** @var CarModel */
protected $carModel;
public function __construct(CarModel $carModel) {
$this->carModel = $carModel;
}
public function getCarsForOwner(Owner $owner) {
return $this->carModel->find('owner = ?', [$owner->id]);
}
}
class CarModel extends PersistenceModel {
const ORM = 'Car';
public function findByColor($color) {
return $this->find('color = ?', [$color]);
}
}