Search code examples
phpzend-framework2zend-formzend-rest

My form is not getting validated in Zend Famework. Why?


I am creating a rest Module for album module of zf2 My Code Snippet for create method :

public function create($data) {
$form=new AlbumForm();
$album = new Album();
$form->setInputFilter($album->getInputFilter());
$form->setData($data);

if ($form->isValid()) {
$album->exchangeArray($form->getData());
$id = $this->getAlbumTable()->saveAlbum($album);
return new JsonModel(array(
        'data' => $this->get($id),
    ));
}

All the functionalities like update,select all,delete are working properly but insertion is not working. I have selected post method through my Advanced rest client application and passing arguments like title=some&artist=someone its not validating form.

The form having values like id Auto-incremented, artist varchar, title varchar,

Please Help for this problem


Solution

  • just got the answer that you have to add this lines to the top of the create method.

    if (empty($data['id'])) $data['id'] = 0;
    

    Its working properly.