ZendFramework2 posting form

Here is the method that should actually send the forms data into the database, but I can't figure out why it doesn't work.There are no errors showing up but the data is not inserted in the table. I would be glad if you can help me out!

//method to add data to the database
public function addAction() {


      //add user info
    $form = new UserForm();
    $form->get('submit')->setValue('add new info');

    $request = $this->getRequest();
    if($request->isPost()){
        $user = new User();
        $form->setData($request->getPost());

        if($form->isValid()){
            $user->exchangeArray($form->getData());//method that gets the validated data
            $this->getUserTable()->saveUser($user);

            return $this->redirect()->toRoute('application',array(
                'controller'=>'user',
                'action'=>'index'
            ));
        }
    }

    //pass it to the view 
    $values = array('form'=>$form);

    $view = new ViewModel($values);
    return $view;
}

views add.phtml

$form = $this->form;

$form->setAttribute('action', $this->url(
                'application', array(
            'controller' => 'user',
            'action' => 'add',
                )
));
echo $this->form()->openTag($form);
echo $this->formHidden($form->get('id'));
echo $this->formRow($form->get('name'));
echo $this->formRow($form->get('email'));

echo $this->formSubmit($form->get('submit'));
echo $this->form()->closeTag();
?>

Answers


 $user = new User();
//user class contains the user information that you can store in the db 
$user->name = "Anime lover";
$user->email = "Anime mail";
$this->getUserTable()->saveUser($user);

$view = new ViewModel($values);
return $view; <- because of this return

-------------- You never pass here----------------------

 //add user info etc....
 $form = new UserForm();

maybe it was for test ? was it ?


Need Your Help

primary key increments based on another key

php mysql laravel

i am developing an accounting system for multiple factories in laravel. I have a bill no which auto increments and is primary key. what i want is to have a separate bill no. for each factory. i.e i...

adding classpath using appassembler-maven-plugin for generating batch file

maven plugins pom.xml appassembler

I am using appassembler from mojo. What I need to do is I have to add a perticular path of the project (say %BASEDIR%\resources) to class path, currently it is adding only %REPO% to the classpath. ...