CodeIgniter Forums

Full Version: It is required that the primary_key be called "id"?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I was doing a simple crud with ci4 and everything went very well until I noticed that to eliminate some element of a table from the forced field table the primary_key has to be called "id"


This is the function that I use to eliminate

elimination of public functions ($ key) {
$ this-> crud_model-> delete ($ key);
return redirect () -> to ("/ crud");
}

When I see the error between a system / Model.php and I see that there is a global variable called primaryKey with "id" as the default value.

My question is, what should I do to be able to use that function without my primary key field being called "id"?

Excuse me for my english, greetings from Cuba
If your table has a different primary key, then set the value of $primaryKey in the Model class that you're using (i.e. UserModel) and it should all work fine.
(08-19-2018, 10:42 AM)kilishan Wrote: [ -> ]If your table has a different primary key, then set the value of $primaryKey in the Model class that you're using  (i.e. UserModel) and it should all work fine.

oh thank you very much, by the way that is in the documentation? in case it was not good that this. I asked the question because I am developing a lib of Crud generator for ci4 ..