Apply for Zend Framework Certification Training

Zend Framework 2





Step 1 create A form
<?php
namespace Application\form;
use Zend\Form\Form;

class MovieForm extends form
{
    public function __construct($name = null) 
    {
        parent::__construct('application');
        $this->setAttribute('method', 'post');
        $this->add(array('name'=>'name','type'=>'text'));
        $this->add(array('name'=>'email','type'=>'text'));
        $this->add(array('name'=>'submit','type'=>'submit','attributes'=>array('value'=>'insert')));
    }
    
    
}
?>
Step 2 create view file

<table border="0" width="500" align="center">
<?php $form = $this->movieform; echo  $this->form()->opentag($form); ?>
    <tr><td> First name     </td><td><?php   echo  $this->formRow($form->get('name')); ?></td></tr>
    <tr><td> Email          </td><td><?php   echo  $this->formRow($form->get('email')); ?></td></tr>
    <tr><td colspan="2" align="center"><?php   echo  $this->formSubmit($form->get('submit')); ?></td></tr>
<?php   echo  $this->form()->closeTag();    ?>
</table>
Step 4 Add Code in controller

public function registrationformAction()
    {
        $movieform = new MovieForm();
        $request = $this->getRequest();
        if ($request->isPost()) {
                $request = $request->getPost();
                $this->getTabledata()->savemovie($request);
                
        }
        return new ViewModel(array('movieform'=>$movieform));
    }

Step 5  Add code in Model 

 public function savemovie($request)
 {
        $data = array('name' => $request['name'],'email'=> $request['email']);
        $this->tableGateway->insert($data);

 }                                    

< List of mysql data usng php in zend framework 2 Directory Structure Of ZendFramework2 >



Ask a question



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


Back to Top