getName() public method

Get the standardized plugin.controller:action name for a route.
public getName ( ) : string
return string
Exemplo n.º 1
0
 /**
  * Add a route to the collection.
  *
  * @param \Cake\Routing\Route\Route $route The route object to add.
  * @param array $options Additional options for the route. Primarily for the
  *   `_name` option, which enables named routes.
  * @return void
  */
 public function add(Route $route, array $options = [])
 {
     $this->_routes[] = $route;
     // Explicit names
     if (isset($options['_name'])) {
         if (isset($this->_named[$options['_name']])) {
             $matched = $this->_named[$options['_name']];
             throw new DuplicateNamedRouteException(['name' => $options['_name'], 'url' => $matched->template, 'duplicate' => $matched]);
         }
         $this->_named[$options['_name']] = $route;
     }
     // Generated names.
     $name = $route->getName();
     if (!isset($this->_routeTable[$name])) {
         $this->_routeTable[$name] = [];
     }
     $this->_routeTable[$name][] = $route;
     // Index path prefixes (for parsing)
     $path = $route->staticPath();
     if (empty($this->_paths[$path])) {
         $this->_paths[$path] = [];
         krsort($this->_paths);
     }
     $this->_paths[$path][] = $route;
     $extensions = $route->getExtensions();
     if (count($extensions) > 0) {
         $this->extensions($extensions);
     }
 }
Exemplo n.º 2
0
 /**
  * Add a route to the collection.
  *
  * @param \Cake\Routing\Route\Route $route The route object to add.
  * @param array $options Additional options for the route. Primarily for the
  *   `_name` option, which enables named routes.
  * @return void
  */
 public function add(Route $route, array $options = [])
 {
     $this->_routes[] = $route;
     // Explicit names
     if (isset($options['_name'])) {
         $this->_named[$options['_name']] = $route;
     }
     // Generated names.
     $name = $route->getName();
     if (!isset($this->_routeTable[$name])) {
         $this->_routeTable[$name] = [];
     }
     $this->_routeTable[$name][] = $route;
     // Index path prefixes (for parsing)
     $path = $route->staticPath();
     if (empty($this->_paths[$path])) {
         $this->_paths[$path] = [];
         krsort($this->_paths);
     }
     $this->_paths[$path][] = $route;
     $extensions = $route->extensions();
     if ($extensions) {
         $this->extensions($extensions);
     }
 }
Exemplo n.º 3
0
 /**
  * Add a route to the collection.
  *
  * Appends the route to the list of routes, and the route hashtable.
  * @param \Cake\Routing\Route\Route $route The route to add
  * @return void
  */
 public function add(Route $route)
 {
     $name = $route->getName();
     if (!isset($this->_routeTable[$name])) {
         $this->_routeTable[$name] = [];
     }
     $this->_routeTable[$name][] = $route;
     $this->_routes[] = $route;
 }
 /**
  * Test getName() with prefixes.
  *
  * @return void
  */
 public function testGetNamePrefix()
 {
     $route = new Route('/admin/:controller/:action', ['prefix' => 'admin']);
     $this->assertEquals('admin:_controller:_action', $route->getName());
     $route = new Route('/:prefix/assets/:action', ['controller' => 'assets']);
     $this->assertEquals('_prefix:assets:_action', $route->getName());
     $route = new Route('/admin/assets/get', ['prefix' => 'admin', 'plugin' => 'asset', 'controller' => 'assets', 'action' => 'get']);
     $this->assertEquals('admin:asset.assets:get', $route->getName());
     $route = new Route('/:prefix/:plugin/:controller/:action/*', []);
     $this->assertEquals('_prefix:_plugin._controller:_action', $route->getName());
 }
Exemplo n.º 5
0
 /**
  * Test getName() with plugins.
  *
  * @return void
  */
 public function testGetNamePlugins()
 {
     $route = new Route('/a/:controller/:action', array('plugin' => 'asset'));
     $this->assertEquals('asset._controller:_action', $route->getName());
     $route = new Route('/a/assets/:action', array('plugin' => 'asset', 'controller' => 'assets'));
     $this->assertEquals('asset.assets:_action', $route->getName());
     $route = new Route('/assets/get', array('plugin' => 'asset', 'controller' => 'assets', 'action' => 'get'));
     $this->assertEquals('asset.assets:get', $route->getName());
 }