Advertisement
dragonbe

A simple login form

Aug 24th, 2011
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.59 KB | None | 0 0
  1. <?php
  2. // file: application/forms/Login.php
  3.  
  4. class Application_Form_Login extends Zend_Form
  5. {
  6.  
  7.     public function init()
  8.     {
  9.         $this->addElement('text', 'username', array (
  10.             'Label' => 'username',
  11.             'Required' => true,
  12.         ));
  13.         $this->addElement('password', 'password', array (
  14.             'Label' => 'password',
  15.             'Required' => true,
  16.         ));
  17.         $this->addElement('submit', 'login', array (
  18.             'Label' => 'Login',
  19.             'Ignore' => true,
  20.         ));
  21.     }
  22.  
  23.  
  24. }
  25.  
  26. <?php
  27. //file: application/controllers/UserController.php
  28.  
  29. class UserController extends Zend_Controller_Action
  30. {
  31.  
  32.     public function init()
  33.     {
  34.         /* Initialize action controller here */
  35.     }
  36.  
  37.     public function indexAction()
  38.     {
  39.         $user = new Application_Model_DbTable_User();
  40.         $users = array ();
  41.         try {
  42.             $users = $user->fetchAll();
  43.         } catch (Zend_Db_Exception $e) {
  44.             echo $e->getMessage() . "<br/>";
  45.         }
  46.         $this->view->users = $users;
  47.     }
  48.  
  49.     public function oneAction()
  50.     {
  51.         $id = $this->getRequest()->getParam('id',0);
  52.         $user = new Application_Model_DbTable_User();
  53.         $this->view->user = $user->find($id);
  54.     }
  55.  
  56.     public function loginAction()
  57.     {
  58.         $form = $this->_getForm();
  59.         $this->view->form = $form;
  60.     }
  61.  
  62.     protected function _getForm()
  63.     {
  64.          return new Application_Form_Login(array (
  65.              'method' => 'post',
  66.              'action' => $this->view->url(array (
  67.                  'controller' => 'user',
  68.                  'action' => 'auth',
  69.              )),
  70.          ));
  71.     }
  72.  
  73.  
  74. }
  75.  
  76.  
  77.  
  78.  
  79.  
  80. <?php // file: application/views/scripts/user/login.php ?>
  81. <?php echo $this->form ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement