How to format template? |
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();
I use blade templating engine in CI, its easier.
In your case using parser you can use php tags.
God Bless CI Contributors
(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();
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>
If you use php tags you dont need curly braces anymore. . from {var} to $var
God Bless CI Contributors
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
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
God Bless CI Contributors
04-28-2017, 03:52 AM
(This post was last modified: 04-28-2017, 03:52 AM by InsiteFX. Edit Reason: fixed spelling error )
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']; What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
There is a library designed for CodeIgniter to simulate Laravel's Blade.
https://github.com/GustMartins/Slice-Library |
Welcome Guest, Not a member yet? Register Sign In |