在第31行的/var/www/docs/Project.com/public/application/controllers/ClientController.php中的非对象上调用成员函数getValue()

时间:2013-12-21 06:13:50

标签: php zend-framework zend-form zend-db

我正在尝试将数据插入数据库并将其显示在网格中但是收到错误调用成员函数获取非对象上的Value()。

这是我的控制器代码。

public function addAction()
{
$form = new Application_Form_user();
$form->submit->setlabel('add');
$this->view->form = $form;

if($this->getRequest()->isPost())
{

    $formData= $this->getRequest()->getPost();

    if($form->isvalid($formData))

        $client= new Application_Model_DbTable_Client();

    $firstname = $formData->getValue('firstname');
            $lastname = $formData->getValue('lastname');
            $email = $formData->getValue('email');

         echo"<pre>";
             print_r($fisrtname);die;   
             $client->addClient($firstname,$lastname,$email);

             $this->_helper->redirector('index');
     }

}

我的型号代码。

public function addClient($firstname,$lastname,$email)
{

  $data=array('fisrtname'=>$firstname,
              'lastname'=>$lastname,
               'email'=>$email);
  $this->insert($data); 
}

这是我的用户表单代码。

class Application_Form_user extends Zend_Form
{
  public function init()
{
    $id = new Zend_Form_Element_Hidden('id');
    $id->addFilter('Int');

    $firstname = new Zend_Form_Element_Text('firstname');
    $firstname->setlabel('firstname');
    $firstname->setRequired('true');


    $lastname = new Zend_Form_Element_Text('lastname');
    $lastname->setlabel('lastname');
    $lastname->setRequired('true');

    $email = new Zend_Form_Element_Text('email');
    $email->setlabel('email');
    $email->setRequired('true');

    $submit = new Zend_Form_Element_Submit('submit');
    $submit->setlabel('submit');
    $submit->setRequired('true');


    $this->addElements(array($id, $firstname, $lastname, $email, $submit));
}                      

}

2 个答案:

答案 0 :(得分:0)

试试这个

$formData  = $this->getRequest()->getPost();
if($form->isvalid($formData))
   $client = new Application_Model_DbTable_Client();
$firstname = $formData['firstname'];
$lastname  = $formData['lastname'];
$email     = $formData['email'];

答案 1 :(得分:0)

抱歉,我在索引名称中出现拼写错误,应该是名字而不是fisrtname。