Zend Framework 2 use Session to login user

564 Views Asked by At

I'm starting on Zend Framework 2, I did the tutorial on album, nos I want to connect users, the sign up is working, so now I diplayed a form, and now I don't know how to use sessions:

http://framework.zend.com/manual/current/en/modules/zend.session.config.html

How I show theform connection:

connection.phtml:

<?php

  $title = 'Connection';
$this->headTitle($title);
?>
<h1><?php echo $this->escapeHtml($title); ?></h1>
<p class="descr">Veuillez remplir entièrement ce formulaire et le valider pour vous inscrire.</p>
<?php
$form->setAttribute('action', $this->url('inscription', array('action' => 'add')));
$form->prepare();

echo $this->form()->openTag($form);
// echo $this->formHidden($form->get('id'));
echo $this->formRow($form->get('pseudo'));
echo "<br/>";
echo $this->formRow($form->get('mdp'));
echo "<br/>";
echo $this->formSubmit($form->get('submit'));
echo $this->form()->closeTag();

Controller:

   public function connectionAction() {
//        return new ViewModel(array(
//            'users' => $this->getUserTable()->fetchAll(),
//        ));


         $form = new ConnectionForm();
         $form->get('submit')->setValue('Se connecter');

         $request = $this->getRequest();
         if ($request->isPost()) {
             $form->setData($request->getPost());

             if ($form->isValid()) {
                 $user->exchangeArray($form->getData());
                 $this->getUserTable()->saveUser($user);

                 return $this->redirect()->toRoute('home');
             }
         }
         return array('form' => $form);
    }
0

There are 0 best solutions below