Add new record
• In module/Dat/src creati directorul Form si in acesta creati fisierul
MyForm.php, cu urmatorul continut:
<?php
namespace DataForm;
// Define an alias for the class name
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'
]
]);
//text
$this->add([
'type'=>'text',
'name'=>'culoare',
'options'=>[
'label'=>'Culoare'
]
]);
//text
$this->add([
'type'=>'text',
'name'=>'nume',
'options'=>[
'label'=>'Nume'
]
]);
//text
$this->add([
'type'=>'text',
'name'=>'culoare',
'options'=>[
'label'=>'Culoare'
]
]);
//submit
$this->add([
'type'=>'submit',
'name'=>'submit',
'attributes'=>[
'value'=>'Submit'
]
]);
//hidden
$this->add([
'type'=>'hidden',
'name'=>'id',
]);
}
}
IndexController
……………………………..
public function addAction()
{
$form=new DataFormMyForm();
$form->get('submit');
$request=$this->getRequest();
if(!$request->isPost()){
return new ViewModel(['form'=>$form]);
}
$flower=new DataModelFlower();
$form->setData($request->getPost());
if(!$form->isValid()){
exit('not valid');
}
$flower->exchangeArray($form->getData());
$this->table->saveFlower($flower);
return $this->redirect()->toRoute('data',['action'=>'index']);
}
src/Model/FlowerTable.php
……………………………..
public function saveFlower(Flower $flower)
{
$data=[
'nume'=>$flower->getNume(),
'culoare'=>$flower->getCuloare(),
'marime'=>$flower->getMarime(),
'pret'=>$flower->getPret()
];
if($flower->getId()){
$this->tableGateway->update($data,['id'=>$flower->getId()]);
}else{
$this->tableGateway->insert($data);
}
}
view/database/index/add.phtml
<?php
$form->setAttribute('action',$this->url('data',['action'=>'add']));
$form->prepare();
echo $this->form()->openTag($form);
echo $this->formRow($form->get('nume'));
echo "<br/><br/>";
echo $this->formRow($form->get('culoare'));
echo "<br/><br/>";
echo $this->formRow($form->get('marime'));
echo "<br/><br/>";
echo $this->formRow($form->get('pret'));
echo "<br/><br/>";
echo $this->formSubmit($form->get('submit'));
echo $this->form()->closeTag();
config/module.config.php
……………..
'add' => [
'type' => Segment::class,
'options' => [
'route' => '/add[/:action]',
'defaults' => [
'controller' => ControllerIndexController::class,
'action' => 'add',
],
],
],
…………………………………

More Related Content

PPTX
12. edit record
PPTX
11. delete record
PPTX
10. view one record
PPTX
8. vederea inregistrarilor
PPTX
PPTX
6. hello popescu 2
PPTX
5. hello popescu
PPTX
4. forme in zend framework 3
12. edit record
11. delete record
10. view one record
8. vederea inregistrarilor
6. hello popescu 2
5. hello popescu
4. forme in zend framework 3

More from Razvan Raducanu, PhD (20)

PPTX
3. trimiterea datelor la vederi
PPTX
2.routing in zend framework 3
PPTX
1. zend framework intro
PPTX
18. images in symfony 4
PPTX
17. delete data
PPTX
16. edit data
PPTX
15. view single data
PPTX
14. add data in symfony4
PPTX
13. view data
PPTX
12.doctrine view data
PPTX
11. move in Symfony 4
PPTX
10. add in Symfony 4
PPTX
9. lower in Symfony 4
PPTX
8. radio1 in Symfony 4
PPTX
7. copy2 in Symfony 4
PPTX
PPTX
5.hello popescu2
PPTX
4.hello popescu
PPTX
1.symfony 4 intro
PPTX
23.simple login with sessions in laravel 5
3. trimiterea datelor la vederi
2.routing in zend framework 3
1. zend framework intro
18. images in symfony 4
17. delete data
16. edit data
15. view single data
14. add data in symfony4
13. view data
12.doctrine view data
11. move in Symfony 4
10. add in Symfony 4
9. lower in Symfony 4
8. radio1 in Symfony 4
7. copy2 in Symfony 4
5.hello popescu2
4.hello popescu
1.symfony 4 intro
23.simple login with sessions in laravel 5
Ad

Recently uploaded (6)

PDF
روح التضرعات في العبادة والصلوات
PPTX
MATERI PEMELIHARAAN ALAT ALAT KESEHATAN PART 1
PPTX
8777952d-95a0-4536-b607-070925cead0a (2).pptx
PDF
ATIVIDADE DE LEITURA - CARNÊ DA LEITURA
PPT
SMKswasta419483567-PPT-MORFOLOGI-IKAN.ppt
PDF
کاریگەری دەربرێنی خۆش و دەربڕێنی ناخۆش لەسەر خوێندکار لە چووارچێوەی بەرێوەبرد...
روح التضرعات في العبادة والصلوات
MATERI PEMELIHARAAN ALAT ALAT KESEHATAN PART 1
8777952d-95a0-4536-b607-070925cead0a (2).pptx
ATIVIDADE DE LEITURA - CARNÊ DA LEITURA
SMKswasta419483567-PPT-MORFOLOGI-IKAN.ppt
کاریگەری دەربرێنی خۆش و دەربڕێنی ناخۆش لەسەر خوێندکار لە چووارچێوەی بەرێوەبرد...
Ad

9. add new record