Apply for Zend Framework Certification Training

Zend Framework 1




Step 1    In Controller Assign name of the text field 

class IndexController extends Zend_Controller_Action
{
     public function indexAction()
     {
        $this->view->assign("action","process");
        $this->view->assign("title","Member registration");
        $this->view->assign("fname","Firstname");
        $this->view->assign("lname","Lastname");
        $this->view->assign("email","email");
        $this->view->assign("uname","username");
        $this->view->assign("pass","password");
        $this->view->assign("submit","Register");
     }
}

Step 2  Create an .phtml file for view // index.phtml

<div id="content">
<table align="center">
<form action="<?php echo $this->escape($this->action);?>" method="post">
  <tr><th><?php echo $this->escape($this->title);?></th></tr>
  <tr>
         <td><?php echo $this->escape($this->fname);?></td>
         <td><input type="text" name="fname"></td>
  </tr>
  <tr>
         <td><?php echo $this->escape($this->lname)?></td>
         <td><input type="text" name="lname"></td>
  </tr>
  <tr>
         <td><?php echo $this->escape($this->email)?></td>
          <td><input type="text" name="email"></td>
  </tr>
  <tr>
         <td><?php echo $this->escape($this->uname)?></td>
         <td><input type="text" name="uname"></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 align="center"><a href="index/loginform">Login</a></td>
  </tr>
</form>
</table>
</div>

Step 3   Create an Process Action to get values of form and to insert data  in Database

public function processAction()
{
    $params = array('host'=>"localhost","username"=>"root",
                     "password"=>"testhello","dbname"=>"zend");
    $db = new Zend_Db_Adapter_Pdo_Mysql($params);
    	
    $request = $this->getRequest();
    $sql="insert into employee(firstname,lastname,email,username,password) 
    values ('".$request->getParam('fname')."','".$request->getParam('lname')."',
    	    '".$request->getParam('email')."','".$request->getParam('uname')."',
    	    '".$request->getParam('pass')."')";
    $db->query($sql);
}
                                    

< How to attatch stylesheet in Zend framework1 How to list Data from Mysql using Zend Framework 1 >



Ask a question



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


Back to Top