How to format template? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10) +--- Thread: How to format template? (/showthread.php?tid=67922) |
How to format template? - PolkaDodge - 04-24-2017 Hi im new to codeigniter and im just wondering on how to format the data from a template. I can format data coming from a row_array result since i dont need to loop it but how can i format data coming from a result_array()?? If i use foreach in controller to format the data i cant loop them in views. Controller: Code: public function loadClients(){ Model: Code: function getClients(){ View: Code: {clients} I would like to be able to number format or date format the result coming from the model in controllers which is Code: $data['clients'] = $this->client_list_model->getClients(); RE: How to format template? - marksman - 04-24-2017 I use blade templating engine in CI, its easier. In your case using parser you can use php tags. RE: How to format template? - PolkaDodge - 04-24-2017 (04-24-2017, 02:44 PM)marksman Wrote: I use blade templating engine in CI, its easier. What do you mean by i can use php tags? i tried doing this in views But this only gives me an error An uncaught Exception was encountered Type: ParseError Message: syntax error, unexpected '{' Code: <td><?php number_format({total_price}); ?></td> And also something like this in controller but this returns only 1 row and i cant get all the data since its not looping Code: $clients = $this->client_list_model->getClients(); RE: How to format template? - PolkaDodge - 04-24-2017 I also would like to add if statements based on some of the data but i dont know how to do it in a template Ex: Controller: $data['clients'] = $this->client_list_model->getClients(); if($data['client_status'] == 'Active'){ //I want to get this and add if statemens, its a data from $data['clients'] $data['filter'] = '<span class="active_filter">' } else if($data['client_status' == 'Inactive'){ $data['filter'] = '<span class="inactive_filter">' } View: {filter}{client_status}</span> RE: How to format template? - marksman - 04-25-2017 If you use php tags you dont need curly braces anymore. . from {var} to $var RE: How to format template? - PolkaDodge - 04-25-2017 Cant i use only the logics in the controller only? cause i want the view for displaying only as much as possible with no php tags or i have no choice RE: How to format template? - marksman - 04-25-2017 I knew you would say that, thats why at first ived recommend blade templating on top of CI. you can do code like Code: <ul> you can benefit more of it's features like extending, yielding, etc. that would make your front looks good I'm currently using it on CI 3.1.4 RE: How to format template? - InsiteFX - 04-28-2017 You can create a method in your controller to create the html output loop through it all assigning it to a variable then assign that variable to your $data['yourName']; RE: How to format template? - Gustavo Martins - 05-02-2017 There is a library designed for CodeIgniter to simulate Laravel's Blade. https://github.com/GustMartins/Slice-Library |