Private Method in UsersController

Par xander, il y a 12 ans


Bonjour, j'ai un petit souci, mon authentification fonctionne bien, mais lors de la redirection j'obtiens ce message d'erreur et je ne vois pas comment le résoudre.

Private Method in UsersController

Error: UsersController::admin_index() cannot be accessed directly.

Notice: If you want to customize this error message, create app\View\Errors\private_action.ctp

Stack Trace

CORE\Cake\Routing\Dispatcher.php line 185 ? Controller->invokeAction(CakeRequest)
CORE\Cake\Routing\Dispatcher.php line 160 ? Dispatcher->_invoke(UsersController, CakeRequest, CakeResponse)
APP\webroot\index.php line 108 ? Dispatcher->dispatch(CakeRequest, CakeResponse)

voici mon code :
UsersController.php

<?php
class UsersController extends AppController{

    public function admin_index() {
    }
    public function beforeFilter(){
            parent::beforeFilter();
            $this->Auth->allow('login');
        }
    public function login(){
        if(!empty($this->request->data)){
            if($this->Auth->login()){
                $this->Session->setFlash("Connexion réussi !", "flash", array('class' => 'success'));
                return $this->redirect('admin_index');
            }else{
                $this->Session->setFlash("Game Over !", "flash", array('class' => 'error'));
            }
        }
    }
    public function logout(){
        $this->Auth->logout();
        return $this->redirect('/');
    }

}

Formulaire de connexion

<section class="admin">
        <h2>Zone Réservé</h2>
        <?= $this->Form->create('User', array('inputDefaults' => array('div' => false, 'class' => 'input-contact'), 'class' => 'contact cb')); ?>
        <?= $this->Form->input('username', array('label' => 'Identifiant', 'placeholder' => "Login", 'required', 'before' => '<p>* Champs obligatoires requis</p><br>')); ?>
        <?= $this->Form->input('password', array('label' => 'Mot de passe', 'placeholder' => "Password", 'required')); ?>
        <?= $this->Form->submit('Se connecter', array('class' => 'submit-contact'));?>
        <?= $this->Form->end(); ?>  
    </section>

cordialement,
Xander

2 réponses

B-Art, il y a 12 ans

Salut Xander,

Ton authentification marche sauf que pour accèder à ta page users > admin_index tu doit passer par une URL de la forme

http://localhost/CakeSite/admin/users/

et non par une URL du type

http://localhost/CakeSite/users/admin_index

Espérant avoir pu t'aider!

A+

xander, il y a 12 ans

Merci de ton aide