Welcome Guest, Not a member yet? Register   Sign In
Mysql Results Conditional
#2

[eluser]johnpeace[/eluser]
Quote:Now using the MVC methodology I’d expect that this would be done in the Controller? since its not exactly a DB query as much as it doing something with a result…however Its also dealing with how the data is formatted and displayed so could it also be done in the view?

Any help on where i should do this would be great, also suggestions on how to achieve it would be handy as I’m still trying to get my head round MVC and the different syntax used here.

Hi! I'm a professional pilot and Codeigniter developer and so took interest in your post when I saw it in my RSS feed...

The MVC architecture is just that...an architecture. Don't forget that you are still the architect and builder and have the freedom to build whatever you like and whatever you would prefer to maintain moving forward.

The way I would handle this would probably be to put it in a function in a helper file. If you're having this problem, you'll probably have other issues where PHP could be used to do some UI stuff in your app. So, a helper like 'user_interface_helper'....

The function would look something like this:

Code:
public function boolean_icon($in) {
    $in = (int)$in; // cast as int just to be sure
    $out = array(0 => 'tick.gif', 1 => 'cross.gif');
    return $out[$in];
}

That will return the filename you want to use...you could modify it to return an <img> tag if you like...

The advantage of putting it in a function in a helper is that you have access to it in ALL of your controllers and views, which gives you a little more flexibility than just coding it as an if/else statement in the view you're working on right now.

As your app grows you'll come up with other ways you want to use the same cross/tick designation of boolean data and have it easy if you're only modifying the way you do it in one place.


Messages In This Thread
Mysql Results Conditional - by El Forum - 12-22-2010, 10:31 AM
Mysql Results Conditional - by El Forum - 12-22-2010, 11:11 AM
Mysql Results Conditional - by El Forum - 12-22-2010, 11:19 AM
Mysql Results Conditional - by El Forum - 12-22-2010, 09:26 PM
Mysql Results Conditional - by El Forum - 12-22-2010, 09:51 PM
Mysql Results Conditional - by El Forum - 12-23-2010, 08:26 AM
Mysql Results Conditional - by El Forum - 12-26-2010, 07:52 AM
Mysql Results Conditional - by El Forum - 12-26-2010, 07:57 AM



Theme © iAndrew 2016 - Forum software by © MyBB