What is $ _GET ['path']?

1

I wonder what it means when someone uses $_GET['path'] ? What would be path ? I thought $_GET would only get information from the URL.

public function get_url_data () {

    // Verifica se o parâmetro path foi enviado
    if ( isset( $_GET['path'] ) ) {

    // Captura o valor de $_GET['path']
    $path = $_GET['path'];

    // Limpa os dados
                        $path = rtrim($path, '/');
                        $path = filter_var($path, FILTER_SANITIZE_URL);

    // Cria um array de parâmetros
    $path = explode('/', $path);

    // Configura as propriedades
    $this->controlador  = chk_array( $path, 0 );
    $this->controlador .= '-controller';
    $this->acao         = chk_array( $path, 1 );

    // Configura os parâmetros
    if ( chk_array( $path, 2 ) ) {
    unset( $path[0] );
    unset( $path[1] );

    // Os parâmetros sempre virão após a ação
    $this->parametros = array_values( $path );
    }Fim if

If possible inform what is path .

    
asked by anonymous 22.12.2017 / 14:17

2 answers

5

The variable $_GET is a super-global used to get values from querystring .

Querystring, would be anything that comes after ? in the URL, example:

http://site.com/pagina?foo=bar&baz=foobar

Could be caught like this:

echo $_GET['foo']; //Exibe bar
echo $_GET['baz']; //Exibe foobar

Most probably $_GET['path'] is used by a .htaccess (or another system that uses mod_rewrite, such as nginx or lighttpd) to rewrite the URL, something like:

If it is .htaccess (apache):

RewriteEngine On
RewriteRule ^(.*)$ rotas.php?path=$1 [L,QSA]

The (.*) takes the URL that is typed and rewrites by passing with parameter to path=<rota> , the user sees something like:

http://site/foo/bar/baz

But in the backend it runs:

http://site/rotas.php?path=foo/bar/baz

What allows you to create "friendly URLs", most likely you are using this MVC framework:

That was created by Luiz to show an example of how to implement MVC with HTTP routes.

    
22.12.2017 / 17:48
0

In php $ _GET it is used to get URL parameters.

For example, if you order a page like link

$ _GET ['path'] would return string 'services'

    
22.12.2017 / 15:58