How to match a model field with a database field? |
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"
10-26-2024, 10:53 PM
(This post was last modified: 10-27-2024, 10:12 PM by InsiteFX. Edit Reason: Spelling error )
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. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
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> CodeIgniter Wizard (CRUD code generator for Mac) instantly scaffolds Bootstrap-based web applications with an administrative interface (admin templates include Bootstrap5) |
Welcome Guest, Not a member yet? Register Sign In |