Cake\Routing\Route\Route::getName PHP Method

getName() public method

Get the standardized plugin.controller:action name for a route.
public getName ( ) : string
return string
    public function getName()
    {
        if (!empty($this->_name)) {
            return $this->_name;
        }
        $name = '';
        $keys = ['prefix' => ':', 'plugin' => '.', 'controller' => ':', 'action' => ''];
        foreach ($keys as $key => $glue) {
            $value = null;
            if (strpos($this->template, ':' . $key) !== false) {
                $value = '_' . $key;
            } elseif (isset($this->defaults[$key])) {
                $value = $this->defaults[$key];
            }
            if ($value === null) {
                continue;
            }
            if (is_bool($value)) {
                $value = $value ? '1' : '0';
            }
            $name .= $value . $glue;
        }
        return $this->_name = strtolower($name);
    }

Usage Example

Example #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);
     }
 }
All Usage Examples Of Cake\Routing\Route\Route::getName