How to dynamically link to a dynamic single db record 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: How to dynamically link to a dynamic single db record view? (/showthread.php?tid=13976) |
How to dynamically link to a dynamic single db record view? - El Forum - 12-14-2008 [eluser]Unknown[/eluser] Looked for this, but new to CI so not sure what to look for. I have a controller which loads a view. The view shows a query listing of records. How do I write a dynamic link for each record result in the list which then opens a single record view? What is best practice in MVC? How to dynamically link to a dynamic single db record view? - El Forum - 12-14-2008 [eluser]thinkigniter[/eluser] Idea 1. In your controller create a function single($record_id = 1) From the view file have a <a> link refering to this controller function. Pass the index_id of the record to this function and load up a second view with the single view option Idea 2. To save server load time create a javascript option that appends the <a> link with a <div> that has all the necessary view fields. Good Coding How to dynamically link to a dynamic single db record view? - El Forum - 12-15-2008 [eluser]Unknown[/eluser] Thank you for your reply and well wishes. I kind of understand what you are saying in idea 1. It is bit unclear to me. With the help of the documentation and the blog screencast tutorial I have been able to get the following so far. Which displays the correct single record in the "single view" when a link is clicked in the "category view": Please keep in mind this is very much in development code, and for illustration purposes only. Do not use on a live site unless you know what you are doing. In the "category view" Unfortunately I can't get the php link I wrote to post properly, so please bear with me until I figure that out. a link with "$row->id" in the href path so you get for example the result "www.yourdomain.com/path/to/2". Where in "row->id" "id" the primary key of the table is. Although I would like to display the title of the article for pretty url's. So you get something like this at its basic level: Code: <?php foreach($query->result() as $row): ?> In the "single view" Code: <?php Please note that in this example the segment in the variable "$article_id" needs to equal the segment location in the link in the "category view". The code above is excluding any modrewrites and routes. How to dynamically link to a dynamic single db record view? - El Forum - 12-15-2008 [eluser]thinkigniter[/eluser] Sorry I can't give you an example the sites security strips out the code, whatever way I format it. Thanks |