I'm facing an error message:
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
To my understanind this error message pops-up because I'm calling a method which doesn't exists in the object. But I'm sure that isUploaded() does exists.
The function isUploaded
is defined in the class Zend_Form_Element_File
. To check if $xls
is an instance of the Zend_Form_Element_File
I debugged the $xls
variable.
Zend_Debug::dump($xls); //OUTPUT: object(Zend_Form_Element_File)#141 (29) {
exit;
Line 30 looks like this:
if ( $xls->isUploaded() ) {
The first thing I did was to check the expression value.
Zend_Debug::dump($xls->isUploaded()); //the output was: bool(true)
exit;
Then I checked the type of the $xls
variable.
echo gettype($xls); //the output was object
exit;
I'm not fully understanding the error. Perhaps, I'm not interpreting the error message as it should be interpreted. Anyway, assistance is needed.
The code snippet: At the controller:
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');
}
At the helper:
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
}
}
}
}