I have a situation where depending on what the value of a uri segment is, my controller will load a different view. Here's what the code looks like in part:
//which view do we load?
if (strpos(strtoupper($data['hardwaremodel']),"HP") !== false)
{
//hp view should be loaded
$data['main_content']='hpad';
}
elseif (strpos(strtoupper($data['hardwaremodel']),"DELL") !== false)
{
$data['main_content']='dellad';
}
//load view.
$this->load->view('includes/template', $data);
For many methods in my controller, I have similar logic. So another method would have the exact same code, but the names of the view would be different dpending on what action the user requested. So for example, instead of loading the Dell address page above ('dellad') it would load the Dell status page ('dellstatus')
I'm wondering if I change my logic so that all the methods in the controller call a new function that determines what view to load for them will simplify things.
I think the function would have to look something like: (just pseudocode)
private function loadview($callingfunctionname, $hardwaremodel)
{
switch ($callingfunctionname)
{
case 'functionA':
if hardware = dell {
return "viewabc"
}
else {
return "viewdef"
}
break;
case 'functionB':
if hardware = dell {
return "view123"
}
else {
return "view456"
}
break;
}//end switch
}
But I don't know that it will really simplify things to it this way. Can you help me improve this code? the other point is that eventually, I will end up with more than 2 hardware types that I have to check for.
Thanks.