A free and open-source book on ZF3 for beginners

Translation into this language is not yet finished. You can help this project by translating the chapters and contributing your changes.

17.11. Agregar la página «No está autorizado»

Luego creamos la página No está autorizado (ver Figura 17.13) a la que se redirigirá al usuario cuando no tenga acceso a una página.

Figura 17.13 Página No está autorizado Figura 17.13 Página No está autorizado

Agregamos la siguiente ruta al archivo module.config.php de módulo User:

return [
    'router' => [
        'routes' => [
            'not-authorized' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/not-authorized',
                    'defaults' => [
                        'controller' => Controller\AuthController::class,
                        'action'     => 'notAuthorized',
                    ],
                ],
            ],
        ],
    ],
];

Luego agregamos el método notAuthorizedAction() al AuthController en el módulo User:

/**
 * Displays the "Not Authorized" page.
 */
public function notAuthorizedAction()
{
    $this->getResponse()->setStatusCode(403);

    return new ViewModel();
}

Finalmente, agregamos el archivo de plantilla de vista not-authorized.phtml dentro de la carpeta user/auth que esta dentro de la carpeta view del módulo User: Finally, add the not-authorized.phtml view template file under the user/auth directory under the User module's view directory:

<?php
$this->headTitle("Not Authorized");
?>

<h1>Not Authorized</h1>

<div class="alert alert-warning">Sorry, you have no permission to see this page.</div>

Si escribimos la URL "http://localhost/not-authorized" en la barra de direcciones del navegador podremos ver la página No está autorizado.


Top