Prado\Web\TUrlManager::parseUrl PHP Метод

parseUrl() публичный Метод

This method is automatically invoked by {@link THttpRequest} when handling a user request. In general, this method should parse the path info part of the requesting URL and generate an array of name-value pairs according to some scheme. The current implementation deals with both 'Get' and 'Path' URL formats. You may override this method to support customized URL format.
См. также: constructUrl
public parseUrl ( ) : array
Результат array list of input parameters, indexed by parameter names
    public function parseUrl()
    {
        $request = $this->getRequest();
        $pathInfo = trim($request->getPathInfo(), '/');
        if (($request->getUrlFormat() === THttpRequestUrlFormat::Path || $request->getUrlFormat() === THttpRequestUrlFormat::HiddenPath) && $pathInfo !== '') {
            $separator = $request->getUrlParamSeparator();
            $paths = explode('/', $pathInfo);
            $getVariables = array();
            foreach ($paths as $path) {
                if (($path = trim($path)) !== '') {
                    if (($pos = strpos($path, $separator)) !== false) {
                        $name = substr($path, 0, $pos);
                        $value = substr($path, $pos + 1);
                        if (($pos = strpos($name, '[]')) !== false) {
                            $getVariables[substr($name, 0, $pos)][] = $value;
                        } else {
                            $getVariables[$name] = $value;
                        }
                    } else {
                        $getVariables[$path] = '';
                    }
                }
            }
            return $getVariables;
        } else {
            return array();
        }
    }

Usage Example

Пример #1
0
 /**
  * Parses the request URL and returns an array of input parameters.
  * This method overrides the parent implementation.
  * The input parameters do not include GET and POST variables.
  * This method uses the request URL path to find the first matching pattern. If found
  * the matched pattern parameters are used to return as the input parameters.
  * @return array list of input parameters
  */
 public function parseUrl()
 {
     $request = $this->getRequest();
     foreach ($this->_patterns as $pattern) {
         $matches = $pattern->getPatternMatches($request);
         if (count($matches) > 0) {
             $this->_matched = $pattern;
             $params = array();
             foreach ($matches as $key => $value) {
                 if (is_string($key)) {
                     $params[$key] = $value;
                 }
             }
             if (!$pattern->getIsWildCardPattern()) {
                 $params[$pattern->getServiceID()] = $pattern->getServiceParameter();
             }
             return $params;
         }
     }
     return parent::parseUrl();
 }