I’m trying to do a import but are getting the same error over and over again.
“Undefined variable $importResults” on line 9 of /srv/www/gfp/public_html/modules/backend/behaviors/importexportcontroller/partials/_import_result_form.php"
My import model looks like this:
class TourImport extends \Backend\Models\ImportModel
{
public $rules = [];
public function importData($results, $sessionKey = null)
{
foreach ($results as $row => $data) {
try {
$tour = new Tour;
$tour->name = $data['name'];
$tour->slug = $data['name'];
$tour->description = $data['description'];
$tour->is_published = 1;
$tour->save();
$this->logCreated();
} catch (Exception $ex) {
$this->logError($row, $ex->getMessage());
}
}
}
}
I know that the problem happens when saving the model, when $tour->save() is removed the errors disappears but obviously the model isn’t saved.
OK to this is what has happen. In the tour model the validation rules have been
public $rules = [
'name' => 'required',
'slug' => 'required|unique:depcore_tours_tours',
'description' => 'required',
'short_description' => 'required',
];
public $customMessages = [
'name.required' => 'The tour name is required.',
'slug.required' => 'The slug is required.',
'slug.unique' => 'The slug must be unique.',
'description.required' => 'The description is required.',
'short_description.required' => '',
];
The error was due to having an empty error message for short_description.required. I blame this on copilot