public function __construct() { // rty to get model name (if empty) by controller name if (empty($this->_modelName)) { $name = substr(get_class($this), 0, -strlen('Controller')); $config = Config::getInstance(); $this->_config = $config; if (file_exists($config['appDir'] . '/' . $config['modelsDir'])) { $this->_modelName = $name; } } $this->_app = Application::getInstance(); }
public function save($compliteTransaction = true) { $modelName = get_called_class(); $limits = Config::getInstance()['limits']; $limit = isset($limits[$modelName]) ? $limits[$modelName] : 0; if (!empty($limit) and $limit <= $this->count()) { throw new Exception("'{$modelName}' model has reached limit of {$limit}"); } $app = Application::getInstance(); try { $app['entityManager']->persist($this); if ($compliteTransaction) { $app['entityManager']->flush(); } } catch (Exception $e) { echo $e->getMessage(); exit; } }
<?php use PollExample\Config; use PollExample\Application; require __DIR__ . '/vendor/autoload.php'; // get config $configArray = (require __DIR__ . '/app/config.php'); $configArray['appDir'] = __DIR__; $config = Config::getInstance($configArray); // set debug messages if (!empty($config['debug'])) { error_reporting(E_ALL); } $app = Application::getInstance($config); return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($app['entityManager']);