![]() |
How to match a model field with a database field? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10) +--- Thread: How to match a model field with a database field? (/showthread.php?tid=91863) |
How to match a model field with a database field? - kuzeyybora - 10-24-2024 I want the variables inside my model to automatically match the database fields. For example, when I write Code: public string $name; Code: name Code: $name = "name" RE: How to match a model field with a database field? - InsiteFX - 10-26-2024 The only way to do that is to read the database table and get all the field names using DBForge. Then you can name your variables. RE: How to match a model field with a database field? - gosocial2 - 10-28-2024 Hi Kuzey, You do not need to define (mapping of) attributes (or variables as you call them) corresponding to the column names in the DB table. The data returned by the model will automatically ensure those attributes are pulled from the database. Example: Code: CREATE TABLE `tbl_products` ( PHP Code: <?php // Or migration if you will: PHP Code: <?php // Model code PHP Code: <?php // Controller Products.php // app/Views/products/list.php : PHP Code: <h1>Products</h1> |