Welcome Guest, Not a member yet? Register   Sign In
Using Models
#1

[eluser]newsmuncher[/eluser]
When using models, if the function fails to get any data from the database for various reasons what is the best way to sort out the variables within the views that are reliant on this getting this information from the model?
#2

[eluser]osci[/eluser]
if I'm passing an array I return false in the model when no data from db and in views I do something like
Code:
if (isset($records) & ($records <> NULL))

if not an array you can return empty strings in your view
#3

[eluser]newsmuncher[/eluser]
How do you do that then?

If you use the model to assign the variables like below:

$model = $this->users->get_user($id);
$this->data['test'] = $users['name'];
#4

[eluser]osci[/eluser]
I don't do this but just to show you what you are asking

Code:
if ($model) //since we are returning false from model for no record
{
   $this->data['test']=$users['name'];
} else {
   $this->data['test']='';
}

You should show another view or redirect somewhere else or do anything if you can't for example get the user data.




Theme © iAndrew 2016 - Forum software by © MyBB