我一直在 zend 中做一个表单,它使用两个表单将数据从用户输入到数据库,这两个表单假设从数据库中的同一个表中共享相同的 id,每次你填写第一个表单的表单时底部有一个保存和继续链接,第二个表单有一个完成的链接。bt 在处理第二个表单时,我当前收到此错误致命错误:在第 43 行调用 C:\xampp\htdocs\Gforms2\application\models\DbTable\Kopano.php 中的未定义方法 stdClass::save()
下面是我的代码
提前致谢
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));
}
}