Ver Mensaje Individual
  #1 (permalink)  
Antiguo 25/08/2011, 10:59
Avatar de ApipeMc
ApipeMc
 
Fecha de Ingreso: septiembre-2010
Ubicación: Medellín, Antioquia, Colombia
Mensajes: 76
Antigüedad: 13 años, 7 meses
Puntos: 1
problemas al devolver Isvalid de un Zend_Form

Proyecto/application/forms/LoginForm.php
Código PHP:
class Application_Form_LoginForm extends Zend_Form
{

    public function 
init()
    {
        
$username = new Zend_Form_Element_Text('username');
        
$username->setLabel('Username:')
                 ->
setRequired(true)
                 ->
setAttrib('id''username')
                 ->
addValidator('NotEmpty'true)
                 ->
addValidator('alnum')
                 ->
setDecorators(array(
                     array(
'ViewHelper',
                           array(
'helper' => 'formText')),
                     array(
'Label',
                           array(
'class' => 'label'))
                 ));

        
$password = new Zend_Form_Element_Password('password');
        
$password->setLabel('Contraseña:')
                 ->
setRequired(true)
                 ->
setAttrib('id''password')
                 ->
addValidator('NotEmpty'true)
                 ->
setDecorators(array(
                     array(
'ViewHelper',
                           array(
'helper' => 'formPassword')),
                     array(
'Label',
                           array(
'class' => 'label'))
                 ));

        
$submit = new Zend_Form_Element_Submit('Entrar');
        
$submit->setAttrib('id''submitbutton')
               ->
setDecorators(array(
                   array(
'ViewHelper',
                   array(
'helper' => 'formSubmit'))
               ));
        
        
$this->setMethod('post');
        
$this->setAction('security/login');
        
$this->addElements(array($username,$password,$submit));
    }

Proyecto/application/controllers/IndexController.php
Código PHP:
class IndexController extends Zend_Controller_Action
{

    public function 
init()
    {
        
/* Initialize action controller here */
    
}

    public function 
indexAction()
    {
        
$form = new Application_Form_LoginForm();
        
$request $this->getRequest();
        
$form->isValid($request->getPost());
        
$this->view->form $form;
    }
    

Proyecto/application/controllers/SecurityController.php
Código PHP:
class SecurityController extends Zend_Controller_Action
{

    public function 
init()
    {
        
/* Initialize action controller here */
    
}

    public function 
indexAction()
    {
        
// action index
    
}
      
    public function 
loginAction()
    {    
        
        
$request $this->getRequest();
        if (!
$request->isPost()) {
            return 
$this->_helper->redirector('index','index');
        }
        
        
$form = new Application_Form_LoginForm();
           if(!
$form->isValid($request->getPost())):
               
$this->view->form $form;
            return 
$this->_helper->redirector('index','index');
        endif;
        
        
$modelSecurity = new Application_Model_Security();
        
        
$username $this->_getParam('username');
        
$password $this->_getParam('password');
        
        if(
$modelSecurity->validarUsuario($username$password)):
            return 
$this->_helper->redirector(indexuser);
        endif;
            
        return 
$this->_helper->redirector('index','index');
    }
    
    public function 
logoutAction()
    {
        
Zend_Auth::getInstance()->clearIdentity();
        
$this->_helper->redirector('index','index'); 
    }
        

Proyecto/application/models/Security.php
Código PHP:
class Application_Model_Security
{
    public function 
validarUsuario($username$password) {
        
    
$authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Db_Table::getDefaultAdapter());
        
$authAdapter->setTableName('users')
                    ->
setIdentityColumn('username')
                    ->
setCredentialColumn('password');
        
$authAdapter->setIdentity($username)
                    ->
setCredential($password);
        
        
//$select = $authAdapter->getDbSelect ();

        
$auth Zend_Auth::getInstance ();
        
$result $auth->authenticate($authAdapter);
        if(
$result->isValid()) :
                    
            return 
true;
            
        endif;
        
        return 
false;
    }

Proyecto/application/views/scrpits/index/index.phml
Código HTML:
Ver original
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3.   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4.   <title>Proyecto</title>
  5.   <link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Cantarell|Philosopher|Copse"></link>
  6.   <link href="css/index_style.css" type="text/css" rel="stylesheet">
  7.   <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript" ></script>
  8. </head>
  9.     <hgroup>
  10.         <h1>Proyecto</h1>
  11.     </hgroup>
  12. </header>    
  13.     <h2 class="left-only">Login</h2>
  14.      <?php
  15.     echo $this->form;
  16.      ?>  
  17. </body>
  18. </html>

El problema es cuando le doy entrar al boton. el realiza bien todas las validaciones.
pero no esta devolviendo los mensajes de las validaciones del Zend_Form.
Soy un poco nuevo en esto y no he podido solucionar ese detalle.

Última edición por ApipeMc; 25/08/2011 a las 11:21