Welcome Guest, Not a member yet? Register   Sign In
Result list page with links to detail page
#1

Hello all,
I'm new to Codeigniter and would like some help finding the resource(s) to solve this problem. I'm attempting to use the Table Class and $this->table->generate($records); to create a result list page (actually, that works fine). I would like each row (each record) to have several links in several cells that take the user to a Detail Page for that record.

In the past, I have written procedural PHP and have used database queries and Repeat Regions with all the HTML required to build a table of results. As the PHP loops through the Do-While statement, a table row is generated for each record. In some of the cells an anchor tag is imbedded with PHP providing the auto-incremented ID (from the query) to link to the detail page for that record.

I would like to do the same thing with Codeigniter, but looking at the Table Library, I see that the CI loop creates a cell for each column blindly using the column heading, there is no obvious way to create an anchor tag for some cells and not for others.

This is something that must be done often by developers, so the problem must be one of nomenclature. Can someone please clue me in on the term I should Google in order to find the standard approach to creating a resultlist page with links to detail pages? Thanks in advance for your time!
Cheers,
Rick
Reply
#2

(11-10-2014, 01:48 PM)rick.emmet Wrote: Hello all,
I'm new to Codeigniter and would like some help finding the resource(s) to solve this problem. I'm attempting to use the Table Class and $this->table->generate($records); to create a result list page (actually, that works fine). I would like each row (each record) to have several links in several cells that take the user to a Detail Page for that record.

In the past, I have written procedural PHP and have used database queries and Repeat Regions with all the HTML required to build a table of results. As the PHP loops through the Do-While statement, a table row is generated for each record. In some of the cells an anchor tag is imbedded with PHP providing the auto-incremented ID (from the query) to link to the detail page for that record.

I would like to do the same thing with Codeigniter, but looking at the Table Library, I see that the CI loop creates a cell for each column blindly using the column heading, there is no obvious way to create an anchor tag for some cells and not for others.

This is something that must be done often by developers, so the problem must be one of nomenclature. Can someone please clue me in on the term I should Google in order to find the standard approach to creating a resultlist page with links to detail pages? Thanks in advance for your time!
Cheers,
Rick

You don't have to use the table library... You can do whatever you like... You can use what you've already described on how you'd do it.
Reply
#3

(This post was last modified: 11-11-2014, 06:54 PM by RobertSF.)

(11-10-2014, 01:48 PM)rick.emmet Wrote: Hello all

Hi, Rick, and welcome.

(11-10-2014, 01:48 PM)rick.emmet Wrote: I would like each row (each record) to have several links in several cells that take the user to a Detail Page for that record.

Easy as Pi... to a million places. Ha! Just kidding! Big Grin

You can give CI a query object and let it create a table from it, but you can also create each row yourself with whatever data you want in the cells.

Here's how I do it. I'm working on a gift exchange application, you know, like a Kris Kringle or Secret Santa. So here I list the gifts a user has put on their wishlist, with links to edit and delete each one.

PHP Code:
$this->table->set_heading('Gift Name''On Gift List''List By''Price');
foreach (
$wishlist as $wish)
{
  
$this->table->add_row($wish['gift'], $wish['glist'], $wish['owner'], $wish['price'],
    
anchor('gifts/edit/' $wish['id'], 'Edit'),
    
anchor('gifts/delete/' $wish['id'], 'Delete'));
}
echo 
$this->table->generate(); 

The above code goes in my view, of course. In my controller, I do the query for the logged-in user's wishlist of gifts and store it in an array called $wishlist. Then I pass that array (along with other stuff) to the view.

In the view, the code sets the table heading and then loops through each gift in the wishlist. The code inside the foreach loop is all one line. The $wish['id'] is the auto-incremented id you're talking about.
Reply
#4

Thank you Tim and Robert,
I didn't want to use the previous code I wrote as it is procedural and I want to use OO code with CI and take advantage of all CI has to offer (might be able to make it work though). Robert, I think I understand what you wrote and will try that use of the anchors in this manner. Thanks a bunch, I'll let you know how it goes!
Cheers,
Rick
Reply
#5

(This post was last modified: 11-13-2014, 06:14 PM by RobertSF.)

(11-13-2014, 12:54 PM)rick.emmet Wrote: I didn't want to use the previous code I wrote as it is procedural and I want to use OO code with CI and take advantage of all CI has to offer

You're welcome, Rick. To make it less procedural, you could take the object returned by your query, and add the links as new properties. If you've not done that dynamically in PHP, here's a page explaining how. Then pass the object to the table->generate class. I've not done it myself, but it should work.

Edit: Wait... that just moves the procedural code to a different part. Guess I don't know how the could be done without a loop through.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB