IF $class = ($value->status == "done") HOW? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12) +--- Thread: IF $class = ($value->status == "done") HOW? (/showthread.php?tid=67236) |
IF $class = ($value->status == "done") HOW? - Fraps900 - 01-30-2017 Guys, I would like to use this to show three different colors on my gantt chart: Code: $class = ($value->status == "done") ? "#336699" : ""; Currently I have one color, that shows done tasks Is this possible to use something like: Code: if $class = ($value->status == "open") ? "#536699" : ""; But of course above code doesn't work. Can You please help me to create some "if" listing for that? RE: IF $class = ($value->status == "done") HOW? - neuron - 01-30-2017 https://davidwalsh.name/php-shorthand-if-else-ternary-operators RE: IF $class = ($value->status == "done") HOW? - ivantcholakov - 01-30-2017 I would propose another way. Make the following helper function, PHP: Code: function get_task_status_class($status) { It is to be used within the views, for example: Code: <span class="task-name <?php echo get_task_status_class($status); ?>"><?php echo html_escape($task_name); ?></span> And add to your CSS: Code: .task-name.open { RE: IF $class = ($value->status == "done") HOW? - Wouter60 - 01-30-2017 You can use the switch conditional statement: PHP Code: switch ($value->status) { RE: IF $class = ($value->status == "done") HOW? - matt... - 01-30-2017 Hello, Why not that : $class = ($value->status == 'open') ? "#536699" : (($value->status == 'in_progress') ? "#796699" : (($value->status == 'done') ? "#336699" : "")); Matt. RE: IF $class = ($value->status == "done") HOW? - dave friend - 01-31-2017 This will also work. PHP Code: if($value->status === "open") I think that @ivantcholakov suggestion of using a CSS file instead of hardcoded color values is a very good idea. Not that I set a good example of that here RE: IF $class = ($value->status == "done") HOW? - Wouter60 - 01-31-2017 @Fraps900, what's your feedback on the suggestions we gave you? |