Cake\Network\Response::location PHP Method

location() public method

Get/Set the Location header value.
public location ( null | string $url = null ) : string | null
$url null | string Either null to get the current location, or a string to set one.
return string | null When setting the location null will be returned. When reading the location a string of the current location header value (if any) will be returned.
    public function location($url = null)
    {
        if ($url === null) {
            $headers = $this->header();
            return isset($headers['Location']) ? $headers['Location'] : null;
        }
        $this->header('Location', $url);
        return null;
    }

Usage Example

 /**
  * Manage redirect for specific buttons that posted.
  *
  * @param Event $event
  * @param array|string $url
  * @param Response $response
  * @return bool
  */
 public function beforeRedirect(Event $event, $url, Response $response)
 {
     if ($this->request->param('prefix') == 'admin') {
         if (isset($this->request->data['apply'])) {
             $response->location(Router::url($this->request->here(false), true));
         }
     }
     return true;
 }
All Usage Examples Of Cake\Network\Response::location