return $cookies; }); $di->setShared('session', function () { $session = new \Phalcon\Session\Adapter\Files(); $session->start(); return $session; }); //Specify routes for modules $di->setShared('router', function () use($config, $routers) { $router = new \Phalcon\Mvc\Router(false); $router->clear(); $router->removeExtraSlashes(true); $router->clear(); $router->setDefaultModule($config->app->defaultApp); $router->setDefaultController($config->app->defaultController); $router->setDefaultAction($config->app->defaultAction); if (!empty($routers)) { foreach ($routers as $name => $rule) { $pattern = $rule->pattern; unset($rule->pattern); $router->add($pattern, $rule->toArray())->setName($name); } } return $router; }); $di->setShared('db', function () use($config) { $connection = new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->name, "charset" => $config->database->charset, "collation" => $config->database->collation)); return $connection; }); $di->set('modelsManager', new \Phalcon\Mvc\Model\Manager()); $di->setShared('url', function () use($config) {
*/ error_reporting(E_ALL); try { /** Define */ define('BASEURL', 'http://phalcon.dev/'); define('CACHE_DATA_ADMIN', '../apps/common/caches/admin'); define('CACHE_DATA_USERS', '../apps/common/caches/users'); define('ADMIN_INFO', serialize(array('name' => 'Thế Phúc', 'email' => '*****@*****.**', 'mailHost' => 'smtp.gmail.com', 'mailPort' => 587, 'mailPassword' => '----'))); /** The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework */ $di = new \Phalcon\DI\FactoryDefault(); /** Registering a router */ $di['router'] = function () { $router = new \Phalcon\Mvc\Router(); $router->setDefaultModule('users'); $router->setDefaultController('index'); $router->setDefaultAction('index'); $adminRoutes = glob(dirname(__DIR__) . "/apps/**/routes/*.php"); foreach ($adminRoutes as $key => $value) { require_once $value; } $router->notFound(array('module' => 'users', 'controller' => 'error', 'action' => 'error404')); $router->removeExtraSlashes(true); return $router; }; /** The URL component is used to generate all kind of urls in the application */ $di->set('url', function () { $url = new \Phalcon\Mvc\Url(); $url->setBaseUri('/'); return $url; }); /** Start the session the first time some component request the session service */
<?php /** * Registering a router */ $router = new \Phalcon\Mvc\Router(false); $router->removeExtraSlashes(true); $router->setDefaultModule("frontend"); $router->setDefaultAction("index"); $router->setDefaultController("index"); /* Frontend */ $router->add('/:controller', array('module' => 'frontend', 'controller' => 1, 'action' => 'index')); $router->add('/:controller/:action', array('module' => 'frontend', 'controller' => 1, 'action' => 2)); $router->add(':controller/:action/:params', array('module' => 'frontend', 'controller' => 1, 'action' => 2, 'params' => 3)); $router->add('/home', array('module' => 'frontend', 'controller' => 'index', 'action' => 'index')); $router->add('/work', array('module' => 'frontend', 'controller' => 'image', 'action' => 'index')); $router->add('/news/:params', array('module' => 'frontend', 'controller' => 'news', 'action' => 'index', 'params' => 1)); $router->add('/contact', array('module' => 'frontend', 'controller' => 'contact', 'action' => 'index', 'params' => 1)); // $router->add("/tin-tuc/{title}.{cid:[0-9]+}", array( // 'module' => 'frontend', // 'controller' => 'news', // 'action' => 'index' // )); /* Backend */ $router->add("/admin", array('module' => 'backend', 'controller' => 'index', 'action' => 'index')); $router->add('/admin/:controller', array('module' => 'backend', 'controller' => 1, 'action' => 'index')); $router->add('/admin/:controller/:action', array('module' => 'backend', 'controller' => 1, 'action' => 2)); $router->add('/admin/:controller/:action/:params', array('module' => 'backend', 'controller' => 1, 'action' => 2, 'params' => 3)); return $router;