0
votes

I have a simple form in my layout default.ctp, this is the code :

<li style="margin-top: 10px;">
                <?php echo $this->Form->create('User', array('action' => 'login')); ?>
                <?php echo $this->Form->input('email',array('label'=> false, 'class' => 'cnx', 'placeholder' => 'E-Mail', 'div' => false)); ?>
                <?php echo $this->Form->input('password',array('label'=> false, 'type'=> 'password', 'class' => 'cnx', 'placeholder' => 'Mot de passe', 'div' => false)); ?>
                <?php
                $options = array('label' => 'Connexion', 'class' => 'btncnx', 'div' => false);
                echo $this->Form->end($options);
                ?>
            </li>

I want to call the action login from my UsersController. The only problem is when i click on the submit button is that CakePHP needs to set the view login . I don't want to create a login.ctp view ...

Missing View Error: The view for UsersController::login() was not found.

my function login in UsersController :

   public function login(){
        if($this->request->is('post')){
            if($this->Auth->login()){
                return $this->redirect($this->Auth->redirect()); 
            }else{
                $this->Session->setFlash("Votre login ou votre mot de passe ne correspond pas","notif",array('type'=>'error'));
            }
        }
    }

How can i do it without creating a view ?

Thanks

2

2 Answers

0
votes
Try this code:
public function login(){
        if($this->request->is('post')){
            if($this->Auth->login()){
                return $this->redirect($this->Auth->redirect()); 
            }else{
                $this->Session->setFlash("Votre login ou votre mot de passe ne correspond pas","notif",array('type'=>'error'));
            }
        }
        $this->render('/Users/default');
    }

More detail here: http://book.cakephp.org/2.0/en/controllers.html

1
votes

This smells like bad practice but OK. Try this in the login() method:

$this->render(null);

If that doesn't work simply create an empty login.ctp. I don't see an issue with that.

Additional best practice tips:

  • Don't use inline CSS
  • Why are you assigning $options and then setting it to end() instead of passing the array directly? Useless variable declaration and in a sum with others a waste of memory.
  • Follow the CakePHP coding standard