我一直在用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));
}
}
答案 0 :(得分: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();
}