Symfony\Component\HttpFoundation\Request::getPathInfo PHP Method

getPathInfo() public method

The path info always starts with a /. Suppose this request is instantiated from /mysite on localhost: * http://localhost/mysite returns an empty string * http://localhost/mysite/about returns '/about' * http://localhost/mysite/enco%20ded returns '/enco%20ded' * http://localhost/mysite/about?var=1 returns '/about'
public getPathInfo ( ) : string
return string The raw path (i.e. not urldecoded)
    public function getPathInfo()
    {
        if (null === $this->pathInfo) {
            $this->pathInfo = $this->preparePathInfo();
        }

        return $this->pathInfo;
    }

Usage Example

Example #1
1
 /**
  * Handles a Request to convert it to a Response.
  *
  * When $catch is true, the implementation must catch all exceptions
  * and do its best to convert them to a Response instance.
  *
  * @param Request $request A Request instance
  * @param int     $type    The type of the request
  *                         (one of HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST)
  * @param bool    $catch   Whether to catch exceptions or not
  *
  * @return Response A Response instance
  *
  * @throws \Exception When an Exception occurs during processing
  */
 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
 {
     try {
         $match = $this->routeMatch;
         if (!$match) {
             $match = $this->router->match($request->getPathInfo());
         }
         if ($match) {
             list($module, $controller, $action) = $this->processRoute($match);
             $request->attributes->add(['_module' => $module, '_controller' => $controller, '_action' => $action]);
             $response = $this->dispatcher->dispatch($match['target'], $match['params']);
         } else {
             $response = $this->dispatcher->dispatch('Home#error', ['message' => 'Halaman tidak ditemukan: ' . $request->getPathInfo()]);
             $response->setStatusCode(Response::HTTP_NOT_FOUND);
         }
     } catch (HttpException $e) {
         if (!$catch) {
             throw $e;
         }
         $response = $this->dispatcher->dispatch('Home#error', ['message' => '[' . $e->getCode() . '] ' . $e->getMessage()]);
         $response->setStatusCode($e->getStatusCode());
     } catch (Exception $e) {
         if (!$catch) {
             throw $e;
         }
         $response = $this->dispatcher->dispatch('Home#error', ['message' => '[' . $e->getCode() . '] ' . $e->getMessage()]);
         $response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
     }
     //$response->setMaxAge(300);
     return $response;
 }
All Usage Examples Of Symfony\Component\HttpFoundation\Request::getPathInfo