Replacing the id column with something more meaningful

Cakephp , for foreign keys, uses the id, which is meaningless ( id’s of 1,2,3,4 is meaningless to a user), so , I want to replace them ( with the username ):
add.ctp file:
echo $this->Form->input(‘clients._ids’, [‘options’ => $clients]);

client, has an autocrement id ( int), and a username ( varchar )

so, replace alist of Ids with the username, how do I change the above line to do that?

thanks in advance

Unclear a add actions for Clients controller?
if Yes, How you can show list of clients when add new client.
if No, you have to set model relations .

I guess you need :
echo $this->Form->input(‘clients._ids’, [‘options’ => $clients]); where $clients = array( 1 => ‘Client 1’, 2 => ‘Client2’);

thanks for the reply.

say, staff have many clients
client is just an id ( int ) and username ( varchar )
when I created a new staff ( in the add.ctp), cakephp will show me a list of clients I can add to the staff ( but it will display a list of Ids 1,2,3,4,5, instead of the client’s usernames )
how can I change it to display a list of usernames instead?

All should works easy in Cake style.
echo $this->Form->input('clients._id);
But check relations in models Staff ad User , if Staff hasMany Users.
I think this view you can cake bake .

I don’t think you understand. It’s very easy, and the solution is also easy ( but I don’t know what it is because I’m new to cakephp )
I have the hasMany relation. I’ve used cake bake all staffs / clients
Cakephp ( by default ) will display ( in the add.ctp for staff) all the client Ids. But displaying Ids ( 1,2,3,4,5) doesn’t mean anything to anyone , so I want to display the username instead of Id.

Show your tables and models (Staff and User).

@johnny2shoes Set the displayField() to username in your ClientsTable::initialize().

It’s additional manipulation :slight_smile:
Cake can not recognize display field with word “name” ?

ok, thanks to all.
That worked ( thanks ADmad).
Can you please explain, ADmad, does changing displayField, in ClientsTable::initialize, only change that one view, add.ctp, for staff, when displaying clients, or does it change every view that displays clients, with Ids, to Username?

Again, how, do I get rid of that red strip at the bottom?