Change record status: 
Project: 
Introduced in branch: 
8.x
Description: 

As of Drupal 8, the core request handling logic has been replaced with Symfony2's HttpKernel, HttpFoundation, and related libraries. This primarily applies to module developers, but has far reaching implications for the entire system.

Of particular note:

The PHP superglobals for $_GET, $_POST, and $_SERVER are deprecated and should not be used, ever. Instead, an instance of the Symfony HttpFoundation\Request class is created during bootstrap and stored in the request() function. Module developers should access that object for any and all information about the HTTP request. (Note: The request function will be removed once that object is accessible via the Dependency Injection Container.)

7.x:

$page = isset($_GET['page']) ? $_GET['page'] : 0;

8.x:

$page = Drupal::service('request')->query->get('page', 0);

See the Request object documentation for more details.

menu_execute_active_handler() has been removed in favor of HttpKernel. In cases where modules need to simulate a new request, they should now create a new request object and issue a subrequest call against the kernel object.

Actual example from comment_permalink():

7.x:

// Set $_GET['q'] and $_GET['page'] ourselves so that the node callback
// behaves as it would when visiting the page directly.
$_GET['q'] = 'node/' . $node->nid;
$_GET['page'] = $page;

// Return the node view.
return menu_execute_active_handler('node/' . $node->nid, FALSE);

8.x:

$request = Drupal::service('request');
$subrequest = Request::create('/node/' . $node->nid, 'GET', $request->query->all(), $request->cookies->all(), array(), $request->server->all());
$subrequest->query->set('page', $page);
// @todo: Convert the pager to use the request object.
$_GET['page'] = $page;
return Drupal::service('http_kernel')->handle($subrequest, HttpKernelInterface::SUB_REQUEST);

Additional implications are noted in separate change notices.

As in Drupal 7, you should not use $_GET['q'], you should use current_path(). Also see [#1659562].

Impacts: 
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done

Comments

Artusamak’s picture

Note that the request service is now called 'request_stack' and that you need to fetch the current request differently:

<?php
    $request = Drupal::service('request_stack');
    $current_request = $request->getCurrentRequest();
    $subrequest = Request::create('/node/' . $node->nid, 'GET', $current_request->query->all(),$current_request->cookies->all(), array(), $current_request->server->all());
?>

Twitter account: @Artusamak
https://happyculture.coop

gaja_daran’s picture

We can get directly using this in D8

$page = \Drupal::request()->query->get('page', 0);