Created
May 16, 2011 22:41
-
-
Save Mikulas/975538 to your computer and use it in GitHub Desktop.
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 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')); | |
} | |
} |
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 | |
//... | |
// 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