Entity class - loop 20 rows and iterate through columns in view |
Hello
I think I miss something and also maybe I don't do the right approach , so lot of thanks for any suggestion I have an entity class named Ticket and in the TicketModel I take advantage of the Ticket entity class Now the point the Home controller I have this "list" method PHP Code: public function list($quantity, $offset) myapp.local/home/list/0/25 as the entity class is conceived, in the view Home/index.php I then can use this PHP Code: <tbody> so far, so good, with this approach it works, but I have more columns to print... so it comes the point that I can't succeed. What it doesn't work in my attempts, is that $tKey is an object (isn't it?) and despite having tried some approaches , I can't get rid of doing the iteration of the $tKey attributes, they are 17 attributes mean 17 columns I mean that instead of echoing so many repetitions of these three lines, one for each $tkey attribute PHP Code: echo "<td>"; rather I'd found of higher cleanness to have a nested foreach that iterates through all the attributes (formerly, given the entity class, through all the columns of the current database row) something like PHP Code: <tbody> well, I have tried almost everything and I can't get rid of have it working also, with the first approach the limit of 25 rows is obey while with the second nested foreach , in the resulting HTML, I can see that are iterated ALL the rows in the database (some 300 rows) and the resulting HTML is just 300 times ... <tr></tr> <tr></tr> <tr></tr> <tr></tr> ... 300 times ... nothing printed inside the tr tag, neither the td tag, so it does mean that it neither enters in the foreach Thank you in advance for any hint regarding this topic Also if you think my approach is wrong, thank you for hinting the better one This is what I see if I dd($tKey)
PHP.net - JsonSerializable::jsonSerialize
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(08-27-2021, 11:51 AM)ikesela Wrote: I try it and got answer : hello, as stated above, I tried it and it works ... though one weird thing happen model PHP Code: public function listTickets($quantity, $offset) controller PHP Code: public function list($quantity, $offset) depite I browse myapp.local/home/list/25/0 they are printed ALL the 300 rows of records in the database I mean, the resulting HTML table, doesn't have 25 rows, instead it has 300 rows Wondering: how is this possible?. Whilst if I use the original code at the begin of this thread, they only prints the expected 25 rows .. really confused about this behavior (08-28-2021, 12:31 AM)Corsari Wrote: WOW ! if you use dd() to see detail, the entities will show two tabs: [properties , available methods] (FOUND HERE IN AVAILABLE METHODS) (08-28-2021, 03:59 AM)Corsari Wrote:(08-27-2021, 11:51 AM)ikesela Wrote: I try it and got answer : How you define your routes? let see it , btw you can test directly data in controller dd(), to see if the result is correct before pass to view. do it step by step until found where the problem. also test query with external mysql client , suggest: HeidiSQL
Oh, good hint, check available methods! Thank you
And yes, I'll go through a step after step testing Thank you for your kind help |
Welcome Guest, Not a member yet? Register Sign In |