lithium\net\http\Router::attach PHP Method

attach() public static method

Example 1: Router::attach('app', array( 'absolute' => true, 'host' => 'localhost', 'scheme' => 'http://', 'prefix' => 'web/tests' )); Example 2: Router::attach('app', array( 'absolute' => true, 'host' => '{:subdomain:[a-z]+}.{:hostname}.{:tld}', 'scheme' => '{:scheme:https://}', 'prefix' => '' )); Attach the variables to populate for the app scope. Router::attach('app', null, array( 'subdomain' => 'www', 'hostname' => 'li3', 'tld' => 'me' ));
public static attach ( $name, $config = null, array $vars = [] )
$vars array
    public static function attach($name, $config = null, array $vars = array())
    {
        if ($name === false) {
            return null;
        }
        if (!isset(static::$_scopes)) {
            static::_initScopes();
        }
        if ($config === null) {
            if ($vars && ($config = static::$_scopes->get($name))) {
                $config['values'] = $vars;
                static::$_scopes->set($name, $config);
            }
            return;
        }
        if (is_array($config) || $config === false) {
            static::$_scopes->set($name, $config);
        }
    }

Usage Example

Example #1
0
 protected function _restoreCtrlContext()
 {
     Router::reset();
     foreach ($this->_context['routes'] as $scope => $routes) {
         Router::scope($scope, function () use($routes) {
             foreach ($routes as $route) {
                 Router::connect($route);
             }
         });
     }
     foreach ($this->_context['scopes'] as $scope => $attachment) {
         Router::attach($scope, $attachment);
     }
     Router::scope($this->_context['scope']);
 }
All Usage Examples Of lithium\net\http\Router::attach