2015-05-20 4 views
0

при сохранении I Получать ошибку:ZF2 вставки данных в БД

values() expects an array of values or Zend\Db\Sql\Select instance

Я думаю, ошибка возникает из:

$this->tableGateway->insert($procedure); 

Я не понимаю, что это неправильно.

Это мой процесс функции:

public function processAction() 
    { 
     if (!$this->request->isPost()){ 
      return $this->redirect()->toRoute(null, array('controller'=>'test', 'action'=>'index')); 
     } 

     $post = $this->request->getPost(); 
     $form = new TestForm(); 
     $inputFilter = new \Postepowania\Form\TestFilter(); 
     $form->setInputFilter($inputFilter); 
     $form->setData($post); 

     if (!$form->isValid()){ 
      $model = new ViewModel(
       array(
        'error' => true, 
        'form' =>$form, 
       ) 
      );    
      $model->setTemplate('postepowania/test/index'); 
      return $model; 
     } 

     $this->createTest($form->getData());  
     //return $this->redirect()->toRoute(null,array('controller' => 'test','action' => 'confirm',)); 
    } 

и функция createTest:

public function createTest(array $data){ 

     $testTable = $this->getServiceLocator()->get('TestTable'); 
     $test = new Test(); 
     $test->exchangeArray($data); 

     $testTable->save($test); 

     return true; 
    } 

Сохранить функция очень проста:

public function save(Test $procedure) 
    { 
     $id = (int)$procedure->id; 
     if($id == 0) 
     { 
      $this->tableGateway->insert($procedure); 
     } 

    } 
+0

Можете ли вы напечатать это выражение? –

ответ

1
$this->tableGateway->insert() 

Глядя на source, insert() требует, чтобы в него был передан массив, а не объект. Я предлагаю преобразовать свой объект в массив, прежде чем передавать его.

+0

+1 Я бы изменил метод 'createTest()'. Вместо '$ testTable-> save ($ test);' use '$ testTable-> save ($ data);' и затем 'return $ test;'. – AlexP

Смежные вопросы