Substitute name for id - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12) +--- Thread: Substitute name for id (/showthread.php?tid=90160) |
Substitute name for id - pchriley - 02-18-2024 Hi, For my first CI4 project I'm developing a document management system for home so I can store scanned paper documents etc. The principal table is for documents (dms_documents) that has fields for file name, document date, category (image, letter, user guide etc) etc. The categories are taken from the category table (dms_category) that populates an HTML select input box on the document add form/View. On startup I have a View page that list all documents in a paged table View, created in my Document Controller and passed to the View thus: Code: class DocumentController extends BaseController PHP Code: // add document form And in the document add form I have this: PHP Code: <div class="form-group"> This all works fine, except that I now want to introduce a foreign key and referential integrity, so that changing the category name/spelling in the dms_category table will cascade through affected records in the dms_documents table. I know I really should change <option value="<?= $cat['name'] ?>" to <option value="<?= $cat['id'] ?>" but then my category field in the dms_documents table says '14' rather than 'Letter', and '14' is displayed in the initial document table view. So, how do I go about substituting the category name for the id in the View? I suspect the answer lies in the Document Controller index() function, and that I need to get the document data as an array then adjust the data that is sent to the View... Thanks RE: Substitute name for id - InsiteFX - 02-21-2024 Associated array 'id' => 'name' RE: Substitute name for id - pchriley - 03-22-2024 (02-21-2024, 05:06 AM)InsiteFX Wrote: Associated array 'id' => 'name' Thanks! |