Foros del Web » Programando para Internet » PHP » Zend »

Problema con Proccesed en Zend_Form

Estas en el tema de Problema con Proccesed en Zend_Form en el foro de Zend en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 18/09/2011, 04:47
 
Fecha de Ingreso: marzo-2006
Mensajes: 230
Antigüedad: 18 años, 1 mes
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. }
  #2 (permalink)  
Antiguo 18/09/2011, 05:05
Avatar de masterpuppet
Software Craftsman
 
Fecha de Ingreso: enero-2008
Ubicación: Montevideo, Uruguay
Mensajes: 3.550
Antigüedad: 16 años, 3 meses
Puntos: 845
Respuesta: Problema con Proccesed en Zend_Form

Que tal utopiko,

Donde seteas la propiedad Application_Form_Signup::processed ?, el Auth Adapter lo tenes creado y configurado ?

Saludos.
__________________
http://es.phptherightway.com/
thats us riders :)

Última edición por masterpuppet; 18/09/2011 a las 05:10
  #3 (permalink)  
Antiguo 18/09/2011, 11:17
 
Fecha de Ingreso: marzo-2006
Mensajes: 230
Antigüedad: 18 años, 1 mes
Puntos: 2
Respuesta: Problema con Proccesed en Zend_Form

Joe pues no idea de como hacer eso que dices para procesar el form, el Auth-Adapter lo he añadido ahora para configurarlo asi:

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.        
  16.         // ...or configure the instance with setter methods
  17.  
  18.         $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
  19.  
  20.         $authAdapter
  21.             ->setTableName('usuarios')
  22.             ->setIdentityColumn('Username')
  23.             ->setCredentialColumn('Password')
  24.         ;
  25.        
  26.         return $authAdapter;
  27.     }
  28.    
  29.     public function preDispatch()
  30.     {
  31.         if (Zend_Auth::getInstance()->hasIdentity()) {
  32.             // If the user is logged in, we don't want to show the login form;
  33.             // however, the logout action should still be available
  34.             if ('logout' != $this->getRequest()->getActionName()) {
  35.                 $this->_helpr->redirector('index', 'index');
  36.             }
  37.         } else {
  38.             // If they aren't, they can't logout, so that action should
  39.             // redirect to the login form
  40.             if ('logout' == $this->getRequest()->getActionName()) {
  41.                 $this->_helpr->redirector('index');
  42.             }
  43.         }
  44.     }
  45.    
  46.     public function indexAction()
  47.     {
  48.         $this->view->form = $this->getForm();
  49.     }
  50.    
  51.       public function processAction()
  52.     {
  53.         $request = $this->getRequest();
  54.  
  55.         // Check if we have a POST request
  56.         if (!$request->isPost()) {
  57.             return $this->_helper->redirector('index');
  58.         }
  59.  
  60.         // Get our form and validate it
  61.         $form = $this->getForm();
  62.         if (!$form->isValid($request->getPost())) {
  63.             // Invalid entries
  64.             $this->view->form = $form;
  65.             return $this->render('index'); // re-render the login form
  66.         }
  67.  
  68.         // Get our authentication adapter and check credentials
  69.         $adapter = $this->getAuthAdapter($form->getValues());
  70.         $auth    = Zend_Auth::getInstance();
  71.         $result  = $auth->authenticate($adapter);
  72.         if (!$result->isValid()) {
  73.             // Invalid credentials
  74.             $form->setDescription('Invalid credentials provided');
  75.             $this->view->form = $form;
  76.             return $this->render('index'); // re-render the login form
  77.         }
  78.  
  79.         // We're authenticated! Redirect to the home page
  80.         $this->_helper->redirector('http://dkjhgfk', 'http://dkjhgfk');
  81.     }
  82.    
  83.     public function logoutAction()
  84.     {
  85.         Zend_Auth::getInstance()->clearIdentity();
  86.         $this->_helper->redirector('http://dkjhgfk'); // back to login page
  87.     }
  88.    
  89.    
  90. }
  #4 (permalink)  
Antiguo 19/09/2011, 09:16
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Respuesta: Problema con Proccesed en Zend_Form

Creo que más bien deberías de usar una Sesión para controlar si ya se proceso (y de forma correcta) el formulario, ya que en el código que expones no hay forma de controlar ni de persistir el valor de $form->processed.

Saludos.
  #5 (permalink)  
Antiguo 20/09/2011, 23:45
Avatar de emiliodeg  
Fecha de Ingreso: septiembre-2005
Ubicación: Córdoba
Mensajes: 1.830
Antigüedad: 18 años, 7 meses
Puntos: 55
Respuesta: Problema con Proccesed en Zend_Form

el problema esta en la linea 73 del controller, como estas haciendo una redirección por mas que setees el valor de procesado se va a perder, o hacer un _forward o devolves siempre la misma vista y q esta se encargue de mostrar el formulario o un mensaje de bienvenida
saludos
__________________
Degiovanni Emilio
developtus.com
  #6 (permalink)  
Antiguo 21/09/2011, 07:07
 
Fecha de Ingreso: marzo-2006
Mensajes: 230
Antigüedad: 18 años, 1 mes
Puntos: 2
Respuesta: Problema con Proccesed en Zend_Form

Vale como devolveria la misma vista??

Sabeis de algun buen manual de Zend, pero que empiece desde 0??A ver se programar en .NET y PHP estructurado a un nivel bastante avanzado y PHP a Objetos y J2EE aun buen nivel, pero no consigo aclararme con este Framework...

Por ejemplo, en este caso no entiendo muy bien el camino que sigue desde el Layout hasta el controlador y la vuelta...
  #7 (permalink)  
Antiguo 21/09/2011, 08:41
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Respuesta: Problema con Proccesed en Zend_Form

Aquí tienes dos articulos que pueden servirte para que entiendas como funciona el proceso de Dispatch de Zend, desde que entra el request al server y hace el render del Layout:

http://devzone.zend.com/article/11978
http://nethands.de/download/zenddispatch_en.pdf

Saludos.

Etiquetas: Ninguno
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:15.