Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/09/2011, 04:47
utopiko
 
Fecha de Ingreso: marzo-2006
Mensajes: 230
Antigüedad: 18 años, 8 meses
Puntos: 2
Problema con Proccesed en Zend_Form

Hola buenos dias, tengo un problema con un Zend_Form de autentificacion, con usuario y contraseña. He seguido las indicaciones de http://bit.ly/2jDe , pero en el helper nunca llega a poner processed y no se como hacerlo funcionar, no tengo ni idea, el codigo mio es el siguiente(Por cierto esta en el Layout, el form):

/application/forms/Signup.php
Código PHP:
Ver original
  1. <?
  2. class Application_Form_Signup extends Zend_Form
  3. {
  4.     public $processed = false;
  5.  
  6.     public function init()
  7.     {
  8.         $this->addElement('text', 'name', array(
  9.             'label' => 'Name',
  10.             'required' => true,
  11.             'validators' => array(
  12.                 array('StringLength', false, array('max'=>75)),
  13.             ),
  14.         ));
  15.         $this->addElement('text', 'email', array(
  16.             'label' => 'Email',
  17.             'required' => true,
  18.             'validators' => array(
  19.                 array('StringLength', false, array('max'=>150)),
  20.                 'EmailAddress',
  21.             ),
  22.         ));
  23.         $this->addElement('submit', 'go', array(
  24.             'label' => 'Sign up',
  25.         ));
  26.     }
  27. }

/application/views/helpers/SignupForm.php

Código PHP:
Ver original
  1. <?php
  2.  
  3. class Zend_View_Helper_SignupForm extends Zend_View_Helper_Abstract
  4. {
  5.     public function signupForm(Application_Form_Signup $form)
  6.     {
  7.         $html = '<h2>Sign up for our newsletter</h2>';
  8.         if($form->processed) {
  9.             $html .= '<p>Thank you for signing up</p>';
  10.         } else {
  11.             $html .= $form->render();
  12.         }
  13.         return $html;
  14.     }
  15. }

/application/controllers/SignupControler.php
Código PHP:
Ver original
  1. <?php
  2.  
  3. class Application_Controller_SignupController extends Zend_Controller_Action
  4. {
  5.     public function getForm()
  6.     {
  7.         return new Application_Form_Signup((array(
  8.             'action' => '/login/process',
  9.             'method' => 'post',
  10.         )));
  11.     }
  12.  
  13.     public function getAuthAdapter(array $params)
  14.     {
  15.         // Leaving this to the developer...
  16.         // Makes the assumption that the constructor takes an array of
  17.         // parameters which it then uses as credentials to verify identity.
  18.         // Our form, of course, will just pass the parameters 'username'
  19.         // and 'password'.
  20.     }
  21.    
  22.     public function preDispatch()
  23.     {
  24.         if (Zend_Auth::getInstance()->hasIdentity()) {
  25.             // If the user is logged in, we don't want to show the login form;
  26.             // however, the logout action should still be available
  27.             if ('logout' != $this->getRequest()->getActionName()) {
  28.                 $this->_helpr->redirector('index', 'index');
  29.             }
  30.         } else {
  31.             // If they aren't, they can't logout, so that action should
  32.             // redirect to the login form
  33.             if ('logout' == $this->getRequest()->getActionName()) {
  34.                 $this->_helpr->redirector('index');
  35.             }
  36.         }
  37.     }
  38.    
  39.     public function indexAction()
  40.     {
  41.         $this->view->form = $this->getForm();
  42.     }
  43.    
  44.       public function processAction()
  45.     {
  46.         $request = $this->getRequest();
  47.  
  48.         // Check if we have a POST request
  49.         if (!$request->isPost()) {
  50.             return $this->_helper->redirector('index');
  51.         }
  52.  
  53.         // Get our form and validate it
  54.         $form = $this->getForm();
  55.         if (!$form->isValid($request->getPost())) {
  56.             // Invalid entries
  57.             $this->view->form = $form;
  58.             return $this->render('index'); // re-render the login form
  59.         }
  60.  
  61.         // Get our authentication adapter and check credentials
  62.         $adapter = $this->getAuthAdapter($form->getValues());
  63.         $auth    = Zend_Auth::getInstance();
  64.         $result  = $auth->authenticate($adapter);
  65.         if (!$result->isValid()) {
  66.             // Invalid credentials
  67.             $form->setDescription('Invalid credentials provided');
  68.             $this->view->form = $form;
  69.             return $this->render('index'); // re-render the login form
  70.         }
  71.  
  72.         // We're authenticated! Redirect to the home page
  73.         $this->_helper->redirector('index', 'index');
  74.     }
  75.    
  76.     public function logoutAction()
  77.     {
  78.         Zend_Auth::getInstance()->clearIdentity();
  79.         $this->_helper->redirector('index'); // back to login page
  80.     }
  81.    
  82.    
  83. }