/** * Example of index action for someone route with the use of the a User model * Using the render view * * @access public * @param MVC $mvc * @return string * @throws \LogicException */ public function index(MVC $mvc) { if (!$mvc->hasCvpp('pdo')) { throw new \LogicException('PDO don\'t exists. Register the MVC\\DataBase\\PdoProvider for use this function.'); } $userModel = new User($mvc->getCvpp('pdo')); $users = $userModel->findAll(); return $mvc->view()->render('User/index.html', array('users' => $users)); }
/** * Register the Console Symfony * * @access public * @param MVC $mvc */ public function register(MVC $mvc) { $application = new Application('Simple PHP MVC', '1.5'); if (!$mvc->hasCvpp('symfony.console')) { $mvc->setCvpp('symfony.console', $application); } foreach ($this->modules as $module) { $module->registerCommands($mvc->getCvpp('symfony.console')); } }
/** * Register the properties of the Doctrine ORM Provider * * @access public * @param MVC $mvc * @return void */ public function register(MVC $mvc) { $default_options = array('params' => array('charset' => null, 'driver' => 'pdo_mysql', 'dbname' => null, 'host' => 'localhost', 'user' => 'root', 'password' => null, 'port' => null), 'dev_mode' => false, 'etities_type' => 'annotations', 'path_entities' => array(), 'proxy_dir' => null); $options = array_merge($default_options, $this->options); if (empty($options['path_entities']) || !is_array($options['path_entities'])) { throw new \Exception('Option path_entities should be an array of path files entities.'); } if ($options['etities_type'] == 'annotations') { $config = Setup::createAnnotationMetadataConfiguration($options['path_entities'], $options['dev_mode'], $options['proxy_dir']); } elseif ($options['etities_type'] == 'yaml' || $options['etities_type'] == 'yml') { $config = Setup::createYAMLMetadataConfiguration($options['path_entities'], $options['dev_mode'], $options['proxy_dir']); } elseif ($options['etities_type'] == 'xml') { $config = Setup::createXMLMetadataConfiguration($options['path_entities'], $options['dev_mode'], $options['proxy_dir']); } if ($mvc->hasCvpp('dbal')) { $entityManager = EntityManager::create($mvc->getCvpp('dbal'), $config); } else { $entityManager = EntityManager::create($options['params'], $config); } if (!$mvc->hasCvpp('dbal')) { $mvc->setCvpp('dbal', $entityManager->getConnection()); } $mvc->setCvpp('em', $entityManager); }
protected function configure(MVC $mvc) { $this->setMvc($mvc)->initSymfonyConsoleProvider()->setApplication($this->mvc->getCvpp('symfony.console')); }
/** * Register Templates Path Twig * * @param MVC $mvc */ public function registerTemplatesPathTwig(MVC $mvc) { $viewsPath = $this->getPath() . '/Resources/views'; if (file_exists(dirname($viewsPath)) && file_exists($viewsPath)) { $mvc->getCvpp('twig.loader.filesystem')->addPath($viewsPath); } }