public function actionIndex() { // redirect to poll list $this->redirect($this->url('poll.index')); return; $html = Application::getTemplateEngine()->render('home/index.html', array('link' => $this->url('poll.index'))); echo $html; }
public function updateStat() { $app = Application::getInstance(); $dql = "SELECT COUNT(a.answer) AS total, SUM(a.answer) as chosen FROM Answer a WHERE a.variant=:variant"; $query = $app['entityManager']->createQuery($dql)->setParameter('variant', $this); $result = $query->getResult(); $this->_total = $result[0]['total']; $this->_chosen = is_null($result[0]['chosen']) ? 0 : $result[0]['chosen']; }
public function actionIndex() { // message for modelless controller if (empty($this->_modelName)) { echo get_class($this) . '->actionIndex(): controller without model'; return; } // get models list $app = Application::getInstance(); $items = Application::getEntityManager()->findAll(); // render model view (if it exists) or default view $html = Application::getTemplateEngine()->render(strtolower($this->_modelName) . '/index.html', array('items' => $items)); if ($html === null) { // fall to default index view $html = $app['templateEngine']->render('default/index.html', array('items' => $items, 'model' => $this->_modelName)); } echo $html; }
public function actionStat($id) { $poll = Poll::findById($id); // update statistic for all variants foreach ($poll->questions as $question) { foreach ($question->variants as $variant) { $variant->updateStat(); } } $pollObj = $poll->formStdObject(); $html = Application::getTemplateEngine()->render('poll/stat.html', array('poll' => $pollObj, 'indexUrl' => $this->url('poll.index'), 'showUrl' => $this->url('poll.show', array('id' => $poll->id)))); echo $html; }
public function url($name, $params = array()) { return Application::getRouter()->url($name, $params); }
<?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']);