本文整理汇总了PHP中Cake\Routing\Router::routes方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::routes方法的具体用法?PHP Router::routes怎么用?PHP Router::routes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Routing\Router
的用法示例。
在下文中一共展示了Router::routes方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: main
/**
* @return void
*/
public function main()
{
self::_loadRoutes();
$formatter = "%15s %-20s %-20s %-10s";
$this->out(sprintf($formatter, 'Method', 'URI Pattern', 'Controller/Action', 'extensions'));
foreach (Router::routes() as $route) {
if (isset($route->defaults['_method'])) {
if (is_array($route->defaults['_method'])) {
$outputMethod = implode(',', $route->defaults['_method']);
} else {
$outputMethod = $route->defaults['_method'];
}
} else {
$outputMethod = 'GET';
}
$uriPattern = $route->template;
if (isset($route->options['_ext']) && $route->options['_ext']) {
$ext = implode(',', $route->options['_ext']);
} else {
$ext = "none";
}
//そもそもControllerが定義されていないものに関しては表示しないようにしている。
if (isset($route->defaults['controller'])) {
$this->out(sprintf($formatter, $outputMethod, $uriPattern, $route->defaults['controller'] . '/' . $route->defaults['action'], $ext));
}
}
}
示例2: check
/**
* Checks a url for the route that will be applied.
*
* @param string $url The URL to parse
* @return null|false
*/
public function check($url)
{
try {
$route = Router::parse($url);
foreach (Router::routes() as $r) {
if ($r->match($route)) {
$name = isset($r->options['_name']) ? $r->options['_name'] : $r->getName();
break;
}
}
$output = [['Route name', 'URI template', 'Defaults'], [$name, $url, json_encode($route)]];
$this->helper('table')->output($output);
$this->out();
} catch (MissingRouteException $e) {
$this->err("<warning>'{$url}' did not match any routes.</warning>");
$this->out();
return false;
}
}
示例3: summary
/**
* Get summary data for the routes panel.
*
* @return int
*/
public function summary()
{
return count(Router::routes());
}
示例4: setupBeforeClass
public static function setupBeforeClass()
{
static::$routes = Router::routes();
}
示例5: testRedirectWithAnotherRouteClass
/**
* Test that redirect() works with another route class.
*
* @return void
*/
public function testRedirectWithAnotherRouteClass()
{
$route1 = $this->getMockBuilder('Cake\\Routing\\Route\\RedirectRoute')->setConstructorArgs(['/mobile\''])->getMock();
$class = '\\' . get_class($route1);
Router::redirect('/mobile', '/', ['status' => 301, 'routeClass' => $class]);
$routes = Router::routes();
$route = $routes[0];
$this->assertInstanceOf($class, $route);
}
示例6: _router
/**
* Get urls from Router
*/
protected function _router()
{
// go through each defined route
foreach (Router::routes() as $route) {
// not supposed to be in sitemap? exclude
if (!isset($route->options['sitemap'])) {
continue;
}
// defaults
$changefreq = isset($route->options['sitemap']['frequency']) ? $route->options['sitemap']['frequency'] : 'monthly';
$priority = isset($route->options['sitemap']['priority']) ? $route->options['sitemap']['priority'] : '0.6';
// dynamic? execute callback if it exists
if (strpos($route->template, '*') !== false || strpos($route->template, ':slug') !== false) {
$callback = $this->_callback($route, true);
if ($callback) {
if (is_array($callback)) {
foreach ($callback as $item) {
$this->_url[] = ['loc' => $item['url'], 'lastmod' => $item['modified'], 'changefreq' => $changefreq, 'priority' => $priority];
}
}
}
// ignore "/*"
continue;
}
// in exclude array?
if (in_array($route->template, $this->exclude)) {
continue;
}
// calculate lastmod
if (isset($route->options['sitemap']['modified'])) {
switch ($route->options['sitemap']['modified']) {
case 'callback':
$lastmod = $this->_callback($route);
break;
case 'ctrl':
$lastmod = $this->_ctrl($route);
break;
default:
$lastmod = $route->options['sitemap']['modified'];
}
} else {
$lastmod = $this->_file($route);
}
$lastmod = (new Time($lastmod ?: time()))->timezone(date_default_timezone_get())->toAtomString();
// add record
$this->_url[] = ['loc' => Router::url($route->template, true), 'lastmod' => $lastmod, 'changefreq' => $changefreq, 'priority' => $priority];
}
}
示例7: testRedirect
/**
* Test that redirect() works.
*
* @return void
*/
public function testRedirect()
{
Router::redirect('/mobile', '/', ['status' => 301]);
$routes = Router::routes();
$route = $routes[0];
$this->assertInstanceOf('Cake\\Routing\\Route\\RedirectRoute', $route);
}
示例8: _buildPrefixes
/**
* Build prefixes for App and Plugins based on configured routes
*
* @return void
*/
protected function _buildPrefixes()
{
$routes = Router::routes();
foreach ($routes as $key => $route) {
if (isset($route->defaults['prefix'])) {
$prefix = Inflector::camelize($route->defaults['prefix']);
if (!isset($route->defaults['plugin'])) {
$this->prefixes[$prefix] = true;
} else {
$this->pluginPrefixes[$route->defaults['plugin']][$prefix] = true;
}
}
}
}
示例9: setRoutes
public function setRoutes()
{
$routes_info = array();
$all_routes = Router::routes();
$ignore = array('index\\');
foreach ($all_routes as $route) {
$reflection = implode('\\', $route->defaults);
if (!in_array($reflection, $ignore)) {
$routes_info[$route->template] = json_encode($route->defaults);
$routes[$route->template] = $reflection . ' -> ' . $route->template;
}
}
$this->controller->set('routes', $routes);
$this->controller->set('routes_info', $routes_info);
}
示例10: _routerPrefixes
/**
* Gets a CamelizedList of all existing router prefixes.
*
* @return array
*/
protected function _routerPrefixes()
{
$cache = static::cache('_routerPrefixes');
if (!$cache) {
$prefixes = [];
foreach (Router::routes() as $route) {
if (empty($route->defaults['prefix'])) {
continue;
} else {
$prefix = Inflector::camelize($route->defaults['prefix']);
if (!in_array($prefix, $prefixes)) {
$prefixes[] = $prefix;
}
}
}
$cache = static::cache('_routerPrefixes', $prefixes);
}
return $cache;
}