![]() |
format string in controller then use it as a function in view - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: format string in controller then use it as a function in view (/showthread.php?tid=16508) |
format string in controller then use it as a function in view - El Forum - 03-09-2009 [eluser]runrun[/eluser] Hi, I have a string similar this in controller: Code: 'close time:' . mktime($rows['close_time']) . 'timeleft:' mktime($rows['close_time']-$rows['current_time']) I want to use it in the view file, like this: Code: <?php foreach($query->result_array() as $rows): ?> Is there any features in CI allow to do this ? format string in controller then use it as a function in view - El Forum - 03-09-2009 [eluser]runrun[/eluser] actually I can use sprintf function in the controller to format the string, but does any one knows how can make the function available in the viewfile ? format string in controller then use it as a function in view - El Forum - 03-09-2009 [eluser]runrun[/eluser] OK this is a so easy question, I shouldn't ask at all. format string in controller then use it as a function in view - El Forum - 03-09-2009 [eluser]xwero[/eluser] Why not do the subtraction before you add the rows to the view file then you can do Code: <?php foreach($rows as $row): ?> format string in controller then use it as a function in view - El Forum - 03-09-2009 [eluser]runrun[/eluser] This is an extension question according to your suggestion. How could I use the database method in the control and get the result to view ? I never know how to do this before, an simple code of the controller and the view would be appreciate. format string in controller then use it as a function in view - El Forum - 03-09-2009 [eluser]xwero[/eluser] Code: // model You could do this in the sql statement too but then you are committing the model to one database, the mysql example Code: $query = $this->db->select('open_time,close_time,(close_time-UNIX_TIMESTAMP()) time_left')->get('shops'); |