Apply for Zend Framework Certification Training

Zend Framework 1




Step 1 Create a login Action in controller 
public function loginformAction()
{
    	$this->view->assign("action","auth");
    	$this->view->assign('user',"Username");
    	$this->view->assign('pass',"Password");
    	$this->view->assign("submit","Login");
}

step 2 Create an subsequent login.phtml file at view
<table align="center">
<form action="<?php echo $this->escape($this->action)?>" method ="post">
	<tr>
               <td><?php echo $this->escape($this->user)?></td>
               <td><input type="text" name="user"></td>
        </tr>
	<tr>
             <td><?php echo $this->escape($this->pass)?></td>
             <td><input type="password" name="pass"></td>
        </tr>
	<tr>
          <td><input type="submit" name="submit" 
                 value="<?php echo $this->escape($this->submit)?>"></td>
	  <td><a href="index">Registration</a></td>
        </tr>
</form>
</table> 

Step 3 Create an Action method to retrieve values of login credentials
public function authAction()
{
    	$request=$this->getRequest();
    	$param= array("host"=>"localhost","username"=>"root",
                                 "password"=>"","dbname"=>"zend");
    	$db= new Zend_Db_Adapter_Pdo_Mysql($param);
    	$authadapter = new Zend_Auth_Adapter_DbTable($db);
        $authadapter->setTableName("employee")
                           ->setIdentityColumn("username")
                           ->setCredentialColumn("password");
    	$username=$request->getParam('user');
    	$password=$request->getParam('pass');
    	$authadapter->setIdentity($username);
    	$authadapter->setCredential($password);
    	$auth = Zend_Auth::getInstance();
    	$result =$auth->authenticate($authadapter);
    	if($result->isValid())
    	{
    		$this->_redirect("/index/list");
    	}else{
    		$this->_redirect("/index/loginform");
    	}
}
public function logoutAction()
{
    // clear everything - session is cleared also!
    Zend_Auth::getInstance()->clearIdentity();
    $this->_redirect("/index/loginform");
}                                    

< How to list Data from Mysql using Zend Framework 1 Delete data in zend framework 1 >



Ask a question



  • Question:
    {{questionlistdata.blog_question_description}}
    • Answer:
      {{answer.blog_answer_description  }}
    Replay to Question


Back to Top