Skip to content

Instantly share code, notes, and snippets.

@Mikulas
Created May 16, 2011 22:41
Show Gist options
  • Save Mikulas/975538 to your computer and use it in GitHub Desktop.
Save Mikulas/975538 to your computer and use it in GitHub Desktop.
<?php
namespace FooModel;
use \Nette\Environment;
abstract class BaseModel extends \Nette\Object
{
/**
* @return \Nette\DI\Container
*/
public static function getContext()
{
return Environment::getContext();
}
/**
* @return \NotORM
*/
public static function getDb()
{
return new \NotORM(self::getContext()->getService('pdo'));
}
}
<?php
//...
// tady to HODNĚ drhne, ale zatím jsem to nevymyslel (neobšlehl) líp
$application = Environment::getApplication();
$application->getContext()->addService('pdo', function() use ($application, $config) {
$c = $config->database;
$pdo = new PDO("$c->engine:host=$c->host;dbname=$c->database", $c->username, $c->password);
$pdo->exec("SET CHARACTER SET utf8");
return $pdo;
});
// .., app run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment