2013-11-15 42 views
0

我一直在zend中使用两种形式将数据从用户输入到数据库中,这两种形式都假设从数据库中的同一个表中共享相同的ID,每次您填写第一种形式在底部具有保存并继续链接的形式,第二种形式具有完成的链接。 bt当处理第二个表单im当前收到此错误致命错误:调用未定义的方法stdClass :: save()在C:\ xampp \ htdocs \ Gforms2 \ application \ models \ DbTable \ Kopano.php on line 43Zend表格/保存相关

在这里我的代码如下

在此先感谢

model db-table kopano 

    public function firstkopanokopano($name, $surname, $nickname, $lastname) 
    { 
     $data = array(
      'name'=> $name, 
      'surname'=> $surname, 
      'nickname'=> $nickname, 
      'lastname'=> $lastname, 

     ); 
     return $this->insert($data); 


    } 

     public function secondkopanokopano($id, $age, $city, $province, $township) 
    { 
     $row = $this->find($id)->current; 

     $row->age = $age; 
     $row->city = $city; 
     $row->province = $province; 
     $row->township = $township; 



     $row->save();//where error is calling from 
     //$this->insert($data); 
    } 

IndexController 

    public function firstkopanoAction() 
     { 
     $form = new Application_Form_Firstkopano(); 


     $this->view->form = $form; 

     if ($this->getRequest()->isPost()) { 
      $formData = $this->getRequest()->getPost(); 
      if ($form->isValid($formData)) {     

       $name = $form->getValue('name'); 
       $surname = $form->getValue('surname'); 
       $nickname = $form->getValue('nickname'); 
       $lastname = $form->getValue('lastname'); 

       $kopano = new Application_Model_DbTable_Kopano(); 
       $id = $kopano->firstkopanoKopano($name, $surname, $nickname, $lastname); 

       //$id = $this->insert($id); 

       $this->_redirect('index/Secondkopano/id/'.$id); 
      } else { 
       $form->populate($formData); 
      } 
     } 
    } 
    public function secondkopanoAction() 
    { 
     $id = $this->_request->getparam('id'); 
     $form = new Application_Form_Secondkopano(); 


     $this->view->form = $form; 

     if ($this->getRequest()->isPost()) { 
      $formData = $this->getRequest()->getPost(); 
      if ($form->isValid($formData)) {     

       $age = $form->getValue('age'); 
       $city = $form->getValue('city'); 
       $province = $form->getValue('province'); 
       $township = $form->getValue('township'); 

       $kopano= new Application_Model_DbTable_Kopano(); 
       $kopano->secondkopanoKopano($id, $age, $city, $province, $township); 



       $this->_helper->redirect('index'); 
      } else { 
       $form->populate($formData); 
      } 
     } 
    } 


forms 1st 

<?php 

class Application_Form_Firstkopano extends Zend_Form 
{ 

    public function init() 
    { 

     $name = new Zend_Form_Element_Text('name'); 
     $name->setLabel('Name') 
      ->setRequired(true) 
      ->addFilter('StripTags') 
      ->addFilter('StringTrim') 
      ->addValidator('NotEmpty'); 

     $surname = new Zend_Form_Element_Text('surname'); 
     $surname->setLabel('Surname') 
      ->setRequired(true) 
      ->addFilter('StripTags') 
      ->addFilter('StringTrim') 
      ->addValidator('NotEmpty'); 

     $nickname = new Zend_Form_Element_Text('nickname'); 
     $nickname->setLabel('Nickname') 
      ->setRequired(true) 
      ->addFilter('StripTags') 
      ->addFilter('StringTrim') 
      ->addValidator('NotEmpty'); 

     $lastname = new Zend_Form_Element_Text('lastname'); 
     $lastname->setLabel('Lastname') 
      ->setRequired(true) 
      ->addFilter('StripTags') 
      ->addFilter('StringTrim') 
      ->addValidator('NotEmpty'); 


     $submit = new Zend_Form_Element_Submit('submit'); 
     $submit->setLabel('Next'); 
     $submit->setAttrib('id', 'submitbutton'); 

     $this->addElements(array($id, $name, $surname, $nickname, $lastname, $submit)); 

    } 


} 


2nd 

<?php 

class Application_Form_Secondkopano extends Zend_Form 
{ 

    public function init() 
    { 
     $age= new Zend_Form_Element_Text('age'); 
     $age->setLabel('Age') 
      ->setRequired(true) 
      ->addFilter('StripTags') 
      ->addFilter('StringTrim') 
      ->addValidator('Digits'); 

     $city = new Zend_Form_Element_Text('city'); 
     $city->setLabel('City') 
      ->setRequired(true) 
      ->addFilter('StripTags') 
      ->addFilter('StringTrim') 
      ->addValidator('NotEmpty'); 

     $province = new Zend_Form_Element_Text('province'); 
     $province->setLabel('Province') 
      ->setRequired(true) 
      ->addFilter('StripTags') 
      ->addFilter('StringTrim') 
      ->addValidator('NotEmpty'); 

     $township = new Zend_Form_Element_Text('township'); 
     $township->setLabel('Township') 
      ->setRequired(true) 
      ->addFilter('StripTags') 
      ->addFilter('StringTrim') 
      ->addValidator('NotEmpty'); 


     $submit = new Zend_Form_Element_Submit('submit'); 
     $submit->setLabel('Next'); 
     $submit->setAttrib('id', 'submitbutton'); 

     $this->addElements(array($id, $age, $city, $province, $township, $submit)); 

    } 


} 

回答

1

更改功能:

public function secondkopanokopano($id, $age, $city, $province, $township) 
     { 
      $row = $this->find($id)->current(); 

      $row->age = $age; 
      $row->city = $city; 
      $row->province = $province; 
      $row->township = $township; 

      return $row->save(); 
     } 
+0

感谢dude.It工作 –