0
Notice: Undefined variable: entryMessage in /var/www/Employee/application/models/EmployeeMapper.php on line 34 Fatal error: Call to a member function setEmployeeId() on a non-object in /var/www/Employee/application/models/EmployeeMapper.php on line 34 

这是我遇到的错误,我尝试显示输入的字段,我检查了数据库并且字段正在保存,我正在发布员工映射器。请检查代码并告诉解决方案,提前致谢

class Application_Model_EmployeeMapper
 {
 protected $_dbTable;

 public function setDbTable($dbTable)
 {
    if (is_string($dbTable)) {
     $dbTable = new $dbTable();
   }
if (!$dbTable instanceof Zend_Db_Table_Abstract) {
  throw new Exception('Invalid table data gateway provided');
}
$this->_dbTable = $dbTable;
return $this;
 }

 public function getDbTable()
 {
if (null === $this->_dbTable) {
  $this->setDbTable('Application_Model_DbTable_Employee');
}
return $this->_dbTable;
 }

 public function fetchAll()
  {
   $table = $this->getDbTable();
   $resultSet = $table->fetchAll($table->select()->order('EMPLOYEE_ID'));
   $entries   = array();
    foreach ($resultSet as $row) {
     $entry = new Application_Model_Employee();
      $entryMessage->setEmployeeId($this->$row->EMPLOYEE_ID)
       ->setFirstName($row->FIRST_NAME)
        ->setLastName($row->LAST_NAME)
        ->setEmail($row->EMAIL)
       ->setPhoneNumber($row->PHONE_NUMBER)
    ->setHireDate($row->HIRE_DATE)
    ->setJobId($row->JOB_ID)
    ->setSalary($row->SALARY);
  $entries[] = $entry; 
}
return $entries;
 }

public function save(Application_Model_Employee $employee)
{
  $data = array(
  'EMAIL'          => $employee->getEmail(),
  'FIRST_NAME'     => $employee->getFirstName(),
  'LAST_NAME'      => $employee->getLastName(),
  'PHONE_NUMBER'   => $employee->getPhoneNumber(),
  'HIRE_DATE'      => $employee->getHireDate(),
  'JOB_ID'         => $employee->getJobId(),
  'SALARY'         => $employee->getSalary(),

  );
4

1 回答 1

0

您收到的错误非常清楚,您应该始终阅读并尝试理解您收到的错误消息,它为您提供了大多数常见问题的解决方案。因此,请始终养成阅读和理解您收到的错误消息的习惯。这里,

Notice: Undefined variable: entryMessage in /var/www/Employee/application/models/EmployeeMapper.php on line 34

注意说,未定义的变量;这意味着您的变量$entryMessage未定义。你得到的错误的第二部分:

Fatal error: Call to a member function setEmployeeId() on a non-object in /var/www/Employee/application/models/EmployeeMapper.php on line 34

非常明显,因为您试图调用尚未定义的函数,但您假设它是一个对象并将其用作对象setEmployeeId()$entryMessage

我假设$entryMessage您使用的应该是$entry

这些很简单,实际上不适合在 SO 中询问。

再一次,我给你的建议是,

  • 始终阅读错误消息的内容,这是您应该用来调试代码中的任何错误的内容
  • 如果您是编程新手,您或许应该使用 IDE(netbeans、eclipse 等),它实际上显示了代码中变量的使用以及函数和语法错误。
  • 总是做你的研究,只有在没有找到或成功的情况下才提出问题,并始终展示你的尝试。其他人会帮助你,但不是为你解决一切。:)
于 2013-03-24T03:29:19.787 回答