我面对错误消息的成员函数:致命错误:调用一个非对象isUploaded()
Fatal error: Call to a member function isUploaded() on a non-object in /www/htdocs/nether/http/123factuur/application/controllers/Helpers/ImportXls.php on line 30
要我understanind此错误消息弹出,因为我打电话的方法这在对象中不存在。但我确信isUploaded()确实存在。
函数isUploaded
在类Zend_Form_Element_File
中定义。要检查$xls
是否是Zend_Form_Element_File
的实例,我调试了$xls
变量。
Zend_Debug::dump($xls); //OUTPUT: object(Zend_Form_Element_File)#141 (29) {
exit;
第30行是这样的:
if ($xls->isUploaded()) {
我做的第一件事是检查表达式的值。
Zend_Debug::dump($xls->isUploaded()); //the output was: bool(true)
exit;
然后我检查了$xls
变量的类型。
echo gettype($xls); //the output was object
exit;
我不完全理解错误。也许,我没有解释错误信息,因为它应该被解释。无论如何,需要援助。
的代码片段: 在控制器:
public function importAction() {
$form = $this->getImportFrom();
$this->view->form = $form;
$this->view->allowedHeaders = array();
$this->importInvoices($form);
$this->importInvoiceArticles($form);
$this->importInvoiceServices($form);
foreach ($this->_lookupIssues as $issue) {
$this->_flashMessenger->addMessage($issue);
}
}
public function importInvoiceArticles($form) {
$model = 'Invoice_article';
$config = Zim_Properties::getConfig($model);
$Model = new Zim_Model($model, $config->model);
$headerMapping = array_flip(array_intersect_key($Model->getHeaders(true), array_flip($this->_allowedArticleImportHeaders)));
$this->getHelper('ImportXls')->handleImport($form, $headerMapping, $Model->getName(), $this->_modelName, null, null, array($this, 'saveImportedArticleData'), 'invoiceArticle');
}
在助手:
class F2g_Helper_ImportXls extends Zend_Controller_Action_Helper_Abstract {
public function handleImport($form, $allowedHeaders, $tableName, $modelName, $onDuplicateImportCallback, $importMethod = null, $saveMethod = null, $name = 'xls') {
if ($this->getRequest()->isPost()) {
$xls = $form->getElement($name);
if ($xls->isUploaded()) {
//some code
}
}
}
}
'在非object'意味着'$ xls'不是任何类的对象。它可能是可变的...... – Umair 2014-10-31 09:28:21
但在echo echotype($ xlss)后显示'object',为什么会这样? – Julian 2014-10-31 09:29:56
你能否粘贴引发这个错误的代码片段? – motanelu 2014-10-31 09:32:18