How do I send an array from the model- to the view-file?
Background: I have a form where name can be put into (View-file). Then I pass this info on to my controller-file, which check if there is information added to the form. If not error message shows up and tells the user that names must be added. If names has been added to the form the controller then pass the info over to the model which check the database if any of the names already exists in the database. If some or all names already exists in the database they are passed on to an array. If the name is NOT added to the database the model-file adds them to the database.
I want to get the array of the names which already are in the database and output these for the user. So this is why I need the array with the names already in the database.
User add:
Mark
Sophie
Dan
Josh
Already in database:
Mark
Dan
Array then contains (should be output to the user):
Mark
Dan
One solution I thought was possible was to add a return statement to the function in the model-file. And retrive the array like this:
$data['nameArray'] = $this->model_name->add_name();
But this won't work, because if the user have missed to add information to the form the else statement will be shown and the $data['nameArray'] will not be defined. Which lead to the error message "Undefined variable", when trying to output it in the view-file.