<?php /** * Phanbook : Delightfully simple forum software * * Licensed under The GNU License * For full copyright and license information, please see the LICENSE.txt * Redistributions of files must retain the above copyright notice. * * @link http://phanbook.com Phanbook Project * @since 1.0.0 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt */ $router = new Phalcon\Mvc\Router(); //$router->setDefaultModule("frontend"); $router->setDefaultNamespace("Phanbook\\Controllers"); $router->setDefaultController('posts'); $router->removeExtraSlashes(true); $router->add('/', ['controller' => 'posts', 'action' => 'index']); //Router /tip,/posts,/questions $router->add('/{collection}', ['controller' => 'posts', 'action' => 'index']); $router->add('/posts/{order:[a-z]+}', ['controller' => 'posts', 'action' => 'index']); //Delete posts $router->add('/posts/delete/{id:[0-9]+}', ['controller' => 'posts', 'action' => 'delete']); $router->add('/questions/delete/{id:[0-9]+}', ['controller' => 'posts', 'action' => 'delete']); $router->add('/tips/delete/{id:[0-9]+}', ['controller' => 'posts', 'action' => 'delete']); $router->add('/hackernews/delete/{id:[0-9]+}', ['controller' => 'posts', 'action' => 'delete']); //View posts $router->add('/posts/{id:[0-9]+}/{slug}', ['controller' => 'posts', 'action' => 'view']); $router->add('/questions/{id:[0-9]+}/{slug}', ['controller' => 'posts', 'action' => 'view']); $router->add('/tips/{id:[0-9]+}/{slug}', ['controller' => 'posts', 'action' => 'view']);
<?php $router = new \Phalcon\Mvc\Router(false); $router->setDefaultController('index'); $router->setDefaultAction('index'); $router->setDefaultNamespace('Controllers'); $router->notFound(['controller' => 'Index', 'action' => 'error']); $router->add('/{id:[0-9]+}', ['controller' => 'index', 'action' => 'index']); $router->add('/', ['controller' => 'index', 'action' => 'index']); $router->add('/login', ['controller' => 'index', 'action' => 'login']); $router->add('/logout', ['controller' => 'index', 'action' => 'logout']); $router->add('/(person|phone|place|user|position)', ['controller' => 1, 'action' => 'index']); $router->add('/(person|phone|place|user|position)/([0-9]+)', ['controller' => 1, 'action' => 'index', 'params' => 2]); $router->add('/(person|phone|place|user|position)/(add|edit|delete|index|search|copy|order)', ['controller' => 1, 'action' => 2]); $router->add('/(person|phone|place|user|position)/(add|edit|delete|index|search|copy)/([0-9]+)', ['controller' => 1, 'action' => 2, 'params' => 3]); return $router;
<?php /* * Define custom routes. File gets included in the router service definition. */ $router = new Phalcon\Mvc\Router(false); $router->removeExtraSlashes(true); $router->setDefaultNamespace('AllSOS\\Controllers'); // Home $router->add('/user/signup', "User::signup"); $router->add('/user/login', "User::login"); $router->add('/user/logout', "User::logout"); $router->add('/user/logoutall', "User::logoutAll"); $router->add('/user/getinfo', "User::getInfo"); $router->add('/user/changeinfo', "User::changeInfo"); $router->add('/user/changelocation', "User::changeLocation"); $router->add('/call/make', "Call::createCall"); $router->add('/call/accept', "Call::acceptCall"); $router->add('/call/reject', "Call::rejectCall"); $router->add('/call/list', "Call::list"); $router->add('/service/list', "Service::list"); $router->add('/service/add', "Service::add"); $router->add('/user/listall', "User::listAll"); $router->notFound(array('controller' => 'ajax', 'action' => 'notFound')); return $router;
<?php /* * Define custom routes. File gets included in the router service definition. */ $router = new Phalcon\Mvc\Router(false); $router->removeExtraSlashes(true); $router->setDefaultNamespace('Notnull\\DailyNews\\Controllers'); // Home $router->add('/user/{username}', "User::add", ['POST'])->setName('add-user'); $router->add('/user/{username}/source', "Source::add", ['POST'])->setName('add-source'); $router->add('/user/{username}/source/delete/{id}', "Source::delete", ['POST'])->setName('delete-source'); $router->add('/user/{username}/source', "Source::list", ['GET'])->setName('list-sources'); $router->add('/fetch', "Source::list", ['GET'])->setName('list-sources'); $router->add('/user/{username}/news', "News::list", ['GET'])->setName('list-news'); // 404 Not Found $router->notFound(array('controller' => 'base', 'action' => 'notFound')); return $router;
* Start the session the first time some component request the session service */ $di->setShared('session', function () { $session = new SessionAdapter(); $session->start(); return $session; }); $di->set('config', $config); /** * Setup router */ $di->set('router', function () { $router = new \Phalcon\Mvc\Router(false); $router->setDefaultController('index'); $router->setDefaultAction('index'); $router->setDefaultNamespace('OPNsense\\Sample\\Api'); $router->add('/', array("controller" => 'index', "action" => 'index')); // // probe registered API modules and create a namespace map // for example, OPNsense\Core\Api will be mapped at http(s):\\host\core\.. // module names should be unique in the application, unless you want to // overwrite functionality (check glob's sorting). // // if the glob for probing the directories turns out to be too slow, // we should consider some kind of caching here // $registered_modules = array(); $controller_dir = __DIR__ . "/../controllers/"; foreach (glob($controller_dir . "*", GLOB_ONLYDIR) as $namespace_base) { foreach (glob($namespace_base . "/*", GLOB_ONLYDIR) as $module_base) { if (strpos($module_base, 'OPNsense/Base') === false) {
* Start the session the first time some component request the session service */ $di->setShared('session', function () { $session = new SessionAdapter(); $session->start(); return $session; }); $di->set('config', $config); /** * Setup router */ $di->set('router', function () { $router = new \Phalcon\Mvc\Router(false); $router->setDefaultController('index'); $router->setDefaultAction('index'); $router->setDefaultNamespace('OPNsense\\Core'); $router->add('/', array("controller" => 'index', "action" => 'index')); // probe registered modules and create a namespace map // for example, OPNsense\Core will be mapped at http(s):\\host\core\.. // module names should be unique in the application, unless you want to // overwrite functionality (check glob's sorting). // // if the glob for probing the directories turns out to be too slow, // we should consider some kind of caching here // $registered_modules = array(); $controller_dir = __DIR__ . "/../controllers/"; foreach (glob($controller_dir . "*", GLOB_ONLYDIR) as $namespace_base) { foreach (glob($namespace_base . "/*", GLOB_ONLYDIR) as $module_name) { if (strpos($module_name, 'OPNsense/Base') === false) { $namespace_name = str_replace('/', '\\', str_replace($controller_dir, '', $module_name));
<?php use Phalcon\Mvc\Application; error_reporting(E_ALL); ini_set('date.timezone', 'Asia/Shanghai'); try { $loader = new \Phalcon\Loader(); $loader->registerNamespaces(array("Phalcon_wifi\\Common\\Models" => "../apps/Common/models", "Phalcon_wifi\\Common\\Controllers" => "../apps/Common/controllers", "Phalcon_wifi\\Common\\Config" => "../apps/Common/config", "Phalcon_wifi\\Common\\Ext" => "../apps/Common/ext", "Phalcon_wifi\\Common\\Validate" => "../apps/Common/validate")); $loader->register(); $di = new \Phalcon\DI\FactoryDefault(); $di["router"] = function () { $router = new \Phalcon\Mvc\Router(); $router->setDefaultModule("Admin"); $router->setDefaultNamespace("Phalcon_wifi\\Admin\\Controllers"); $router->add('/:controller/:action/:params', array('module' => 'Admin', 'controller' => 1, 'action' => 2, 'params' => 3))->setName("common"); return $router; }; $di["url"] = function () use($di) { $url = new \Phalcon\Mvc\Url(); $url->setBaseUri($di->get("config")->get("common")["baseuri"]); return $url; }; $di["session"] = function () { $session = new \Phalcon\Session\Adapter\Files(); $session->start(); return $session; }; $di["db"] = function () use($di) { $config = $di->get("config")->get("common")["db"]; $connection = new \Phalcon\Db\Adapter\Pdo\Mysql(array("host" => $config["host"], "username" => $config["username"], "password" => $config["password"], "dbname" => $config["dbname"], "charset" => $config["charset"])); $eventsManager = new \Phalcon\Events\Manager();
class AjaxFilter { public function check($uri, $route) { return $_SERVER['HTTP_X_REQUESTED_WITH'] == 'xmlhttprequest'; } } $router->add('...', array())->beforeMatch(array(new AjaxFilter(), 'check')); // 限制主机名(Hostname Constraints) $router->add('...', array())->setHostName('admin.company.com'); $router->add('...', array())->setHostName('([a-z+]).company.com'); Phalcon\Mvc\Router\Group::setHostName('blog.mycompany.com'); // 设置默认路径(Setting default paths) //Setting a specific default $router->setDefaultModule('backend'); $router->setDefaultNamespace('Backend\\Controllers'); $router->setDefaultController('index'); $router->setDefaultAction('index'); //Using an array $router->setDefaults(array('controller' => 'index', 'action' => 'index')); // 处理结尾额外的斜杆(Dealing with extra/trailing slashes) $router->removeExtraSlashes(true); // 没有找到路径(Not Found Paths) $router->notFound(array("controller" => "index", "action" => "route404")); $router->handle(); $di->set('router', function () { require __DIR__ . '/../app/config/routes.php'; return $router; }); // *** Url *** $url->setBaseUri('/');
<?php $router = new \Phalcon\Mvc\Router(); $router->add("/:controller/:action", array('controller' => 1, 'action' => 2))->convert('action', function ($action) { return str_replace('-', '', $action); }); $router->add("/:controller/:action/:params", array('controller' => 1, 'action' => 2, "seo" => 3))->convert('action', function ($action) { return str_replace('-', '', $action); }); $router->add("/coba", array('module' => 'backend', 'namespace' => 'HaiQuan\\Backend\\Controllers')); $router->add("/coba/:controller", array('module' => 'backend', 'namespace' => 'HaiQuan\\Backend\\Controllers', 'controller' => 1, 'action' => "index")); $router->add("/coba/:controller/:action", array('module' => 'backend', 'namespace' => 'HaiQuan\\Backend\\Controllers', 'controller' => 1, 'action' => 2))->convert('action', function ($action) { return str_replace('-', '', $action); }); $router->add("/tin-tuc/:params", array('module' => 'frontend', "controller" => "tintuc", "action" => "index", "seo" => 1)); $router->add("/tong-hop-tin-tuc", array('module' => 'frontend', "controller" => "tintuc", "action" => "tonghoptintuc", "seo" => 1)); $router->add("/", array('module' => 'frontend', 'namespace' => 'HaiQuan\\Frontend\\Controllers', "controller" => "index", "action" => "index")); $router->add("/tu-van", array('module' => 'frontend', 'namespace' => 'HaiQuan\\Frontend\\Controllers', "controller" => "tuvancauhoi", "action" => "index")); $router->add("/thu-tuc", array('module' => 'frontend', 'namespace' => 'HaiQuan\\Frontend\\Controllers', "controller" => "thutuc", "action" => "index")); $router->add("/van-ban/:params", array('module' => 'frontend', "controller" => "vanban", "action" => "index", "seo" => 1)); $router->add("/tong-hop-van-ban", array('module' => 'frontend', "controller" => "vanban", "action" => "tonghopvanban", "seo" => 1)); $router->setUriSource(\Phalcon\Mvc\Router::URI_SOURCE_GET_URL); $router->setDefaultModule("frontend"); $router->setDefaultNamespace("HaiQuan\\Frontend\\Controllers"); $router->removeExtraSlashes(true); $router->handle(); return $router;
public function setRoutes($file) { // Load Routes $routes = (include $file); // Setup Routes $di = $this->getDI(); $di->set('router', function () use($routes) { $router = new \Phalcon\Mvc\Router(); $router->setDefaultNamespace('Controllers'); // Setup Routes foreach ($routes as $uri => $route) { $router->add($uri, $route); } //$router->notFound(array('controller' => 'notfound', 'action' => 'index')); $router->handle(); return $router; }); $this->setDI($di); }