O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

4. forme in zend framework 3

21 visualizações

Publicada em

http://www.rraducanu.ro

Publicada em: Educação
  • Login to see the comments

  • Seja a primeira pessoa a gostar disto

4. forme in zend framework 3

  1. 1. Forme in Zend framework 3
  2. 2. • Creati modulul Forme si apoi efectuati toate configurarile necesare. composer update !!!!!
  3. 3. • Creati directorul module/Forme/src/Form si in acesta fisierul MyForm.php Acesata va reprezenta clasa forma “sablon” in care vor trebui definite toate controalele ce urmeaza a fi invocate in vederi.
  4. 4. MyForm.php <?php namespace FormeForm; use ZendFormForm; // A feedback form model class MyForm extends Form { // Constructor. public function __construct() { parent::__construct('myform');//my_form este numele formei $this->setAttribute('method', 'post'); //text $this->add([ 'type'=>'text', 'name'=>'nume', 'options'=>[ 'label'=>'Nume' ] ]);
  5. 5. //text $this->add([ 'type'=>'text', 'name'=>'prenume', 'options'=>[ 'label'=>'Prenume' ] ]); //password $this->add([ 'type'=>'password', 'name'=>'password', 'options'=>[ 'label'=>'Password' ] ]); //textarea $this->add([ 'type'=>'textarea', 'name'=>'textarea', 'attributes'=>[ 'rows'=>'5', 'cols'=>'30', ], 'options'=>[ 'label'=>'Textarea', ] ]);
  6. 6. //radio $this->add([ 'type'=>'radio', 'name'=>'radio', 'options'=>[ 'label'=>'Choose: ', 'value_options'=>[ '0'=>'Negruzzi', '1'=>'National', '2'=>'Informatica', ], ] ]); //checkbox1 $this->add([ 'type'=>'checkbox', 'name'=>'check1', 'options'=>[ 'label'=>'Iasi', 'check_value'=>'Iasi', 'uncheck_value'=>'0' ] ]);
  7. 7. //checkbox2 $this->add([ 'type'=>'checkbox', 'name'=>'check2', 'options'=>[ 'label'=>'Bucuresti', 'check_value'=>'Bucuresti', 'uncheck_value'=>'0' ] ]); //checkbox3 $this->add([ 'type'=>'checkbox', 'name'=>'check3', 'options'=>[ 'label'=>'Cluj', 'check_value'=>'Cluj', 'uncheck_value'=>'0' ] ]);
  8. 8. //select $this->add([ 'type'=>'select', 'name'=>'dropdown', 'options'=>[ 'label'=>'Choose: ', 'value_options'=>[ '0'=>'Negruzzi', '1'=>'National', '2'=>'Informatica', ], ] ]); //list select $this->add([ 'type'=>'MonthSelect', 'name'=>'month', 'options'=>[ 'label'=>'Select a month and a year. ', 'min_year'=>'2000', ] ]);
  9. 9. //submit $this->add([ 'type'=>'submit', 'name'=>'submit', 'attributes'=>[ 'value'=>'Save' ] ]); } }
  10. 10. module/Forme/view/forme/index/index.phtml <?php $title="Form controls"; $this->headTitle($title); ?> <h1><?php echo $this->escapeHtml($title);?></h1> <?php $form=$this->form; //$form->setAttribute('action',$this->url('my_form',['action'=>'show'])); $form->prepare(); echo $this->form()->openTag($form);
  11. 11. echo $this->formRow($form->get('nume')); echo '<br/>'; echo $this->formRow($form->get('prenume')); echo '<br/>'; echo $this->formRow($form->get('password')); echo '<br/>'; echo $this->formRow($form->get('textarea')); echo '<br/>'; echo $this->formRow($form->get('radio')); echo '<br/>'; echo $this->formRow($form->get('check1')); echo $this->formRow($form->get('check2')); echo $this->formRow($form->get('check3')); echo '<br/>';
  12. 12. echo $this->formRow($form->get('dropdown')); echo '<br/>'; echo $this->formRow($form->get('month')); echo '<br/>'; echo $this->formSubmit($form->get('submit')); echo '<br/>'; echo $this->form()->closeTag(); ?>
  13. 13. module/Forme/src/Controller/IndexController.php <?php namespace FormeController; use ZendMvcControllerAbstractActionController; use ZendViewModelViewModel; class IndexController extends AbstractActionController { public function indexAction() { $form=new FormeFormMyForm(); return new ViewModel(['form'=>$form]); } }
  14. 14. module/Forme/config/module.config.php namespace Forme; use ZendRouterHttpLiteral; use ZendRouterHttpSegment; use ZendServiceManagerFactoryInvokableFactory; …………………………….
  15. 15. …………………………….. 'forme' => [ 'type' => Segment::class, 'options' => [ 'route' => '/forme[/:action]', 'defaults' => [ 'controller' => ControllerIndexController::class, 'action' => 'index', ], …………………………………
  16. 16. 'view_manager' => [ 'display_not_found_reason' => true, 'display_exceptions' => true, 'doctype' => 'HTML5', 'not_found_template' => 'error/404', 'exception_template' => 'error/index', 'template_map' => [ 'layout/layout' => __DIR__ . '/../view/layout/layout.phtml', 'forme/index/index' => __DIR__ . '/../view/forme/index/index.phtml', 'error/404' => __DIR__ . '/../view/error/404.phtml', 'error/index' => __DIR__ . '/../view/error/index.phtml', ],

×