本文整理汇总了PHP中Phalcon\Mvc\Router::setDefaults方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::setDefaults方法的具体用法?PHP Router::setDefaults怎么用?PHP Router::setDefaults使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Mvc\Router
的用法示例。
在下文中一共展示了Router::setDefaults方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Router
<?php
use Phalcon\Mvc\Router;
$router = new Router();
//Remove trailing slashes automatically
$router->removeExtraSlashes(true);
//main route
$router->add("/", array('controller' => 'index', 'action' => 'index'));
//GET VERB - GET ELEMENT
//Get elemets of relationship. Ex: /department/2/user
$router->addGet('/:controller/:int/([a-zA-Z0-9_-]+)', array('controller' => 1, 'action' => "list", 'id' => 2, 'relationship' => 3));
//Get one element. Ex: /user/2
$router->addGet('/:controller/:int', array('controller' => 1, 'action' => "get", 'id' => 2));
//Get all elements. Ex: /user
$router->addGet('/:controller', array('controller' => 1, 'action' => "list"));
//POST VERB - CREATE ELEMENT
//Create a new element. Ex: /user
$router->addPost('/:controller', array('controller' => 1, 'action' => "save"));
//PUT VERB - UPDATE ELEMENT
//Update a new element. Ex: /user
$router->addPut('/:controller/:int', array('controller' => 1, 'action' => "save", 'id' => 2));
//DELETE VERB - UPDATE ELEMENT
//Update a new element. Ex: /user
$router->addDelete('/:controller/:int', array('controller' => 1, 'action' => "delete", 'id' => 2));
//not founded route
$router->notFound(array('controller' => 'error', 'action' => 'page404'));
$router->setDefaults(array('controller' => 'index', 'action' => 'index'));
return $router;
示例2: Router
/**
* 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
*/
use Phalcon\Mvc\Router\Group;
use Phalcon\Mvc\Router;
$router = new Router(false);
$router->setDefaults(['module' => 'frontend', 'controller' => 'posts', 'action' => 'index']);
$router->removeExtraSlashes(true);
/*
* All defined routes are traversed in reverse order until Phalcon\Mvc\Router
* finds the one that matches the given URI and processes it, while ignoring the rest.
*/
$frontend = new Group(['module' => 'frontend']);
$frontend->add('/:controller/:action/:params', ['controller' => 1, 'action' => 2, 'params' => 3]);
$frontend->add('/:controller/:int', ['controller' => 1, 'id' => 2]);
$frontend->add('/:controller/:int/{slug:[a-z\\-]+}', ['controller' => 1, 'id' => 2, 'slug' => 3, 'action' => 'view']);
$frontend->add('/posts/:int/{slug:[a-z\\-]+}', ['id' => 1, 'slug' => 2, 'action' => 'view']);
$frontend->add('/:controller[/]?', ['controller' => 1]);
$frontend->add('/blog/{id:[0-9]+}/{slug:[a-z\\-]+}', ['controller' => 'posts', 'action' => 'view']);
$frontend->add('/questions/{id:[0-9]+}/{slug:[a-z\\-]+}', ['controller' => 'posts', 'action' => 'view']);
$frontend->add('/questions/new', ['controller' => 'posts', 'action' => 'new']);
$frontend->add('/');
示例3: Router
<?php
use Phalcon\Mvc\Router;
$router = new Router();
//路由
$router->add('/', array('namespace' => 'Index\\Controllers', 'controller' => 'Index', 'action' => 'index'));
$router->add('/(index|Index)/:controller/:action/:params', array('namespace' => 'Index\\Controllers', 'controller' => 2, 'action' => 3, 'params' => 4));
$router->add('/(App|app)/:controller/:action/:params', array('namespace' => 'App\\Controllers', 'controller' => 2, 'action' => 3, 'params' => 4));
$router->add('/(Agent|agent)/:controller/:action/:params', array('namespace' => 'Agent\\Controllers', 'controller' => 2, 'action' => 3, 'params' => 4));
$router->notFound(array("namespace" => 'System\\Controllers', "controller" => "Error", "action" => "error404"));
$router->setDefaults(array('namespace' => 'Index\\Controllers', 'controller' => 'Index', 'action' => 'index'));
return $router;
示例4: Router
<?php
use Phalcon\Mvc\Router\Group;
use Phalcon\Mvc\Router;
$router = new Router(false);
$router->setDefaults(['controller' => 'tests', 'action' => 'index']);
$router->removeExtraSlashes(true);
$prefix = '/' . VERSION . '/';
//tests
$tests = new Group(['controller' => 'tests']);
$tests->setPrefix($prefix . 'tests');
$tests->addGet('', ['action' => 'index']);
$tests->addGet('/{id:[0-9]+}', ['action' => 'view']);
$tests->addPost('/new', ['action' => 'new']);
$tests->addPut('/{id:[0-9]+}', ['action' => 'update']);
//task
$tasks = new Group(['controller' => 'task']);
$tasks->setPrefix($prefix . 'tasks');
$tasks->addGet('', ['action' => 'index']);
$tasks->addGet('/{id:[0-9]+}', ['action' => 'view']);
$tasks->addPost('/new', ['action' => 'new']);
$tasks->addPut('/{id:[0-9]+}', ['action' => 'update']);
//token
$token = new Group(['controller' => 'token']);
$token->setPrefix($prefix . 'token');
$token->add('', ['action' => 'index']);
//mount
$router->mount($token);
$router->mount($tests);
$router->mount($tasks);
return $router;
示例5: setDefaults
public function setDefaults(array $defaults)
{
return parent::setDefaults($defaults);
}