Question

I have a database table with the following structure:

CREATE TABLE IF NOT EXISTS `users` (
  `id` varchar(15) NOT NULL,
  `userName` varchar(255) NOT NULL,
  `pass_word` varchar(32) NOT NULL,
  `privilege` char(1) DEFAULT 'C',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=cp1256;

You may notice that the id field is not int. It is varchar. The problem here, when I try to bake this table into model, controller and use scaffolding, I got the following screen shot with new user view:

enter image description here

You should notice that there is no id field in which I want to enter it as varchar. Also setting validation to the id to be alphanumeric and notempty, prevents the record to be added.

Is there any solution for this without need to change the table structure?

Was it helpful?

Solution

To make this visible, in your add view, add this line:

    echo $this->Form->input('id', array('type' => 'text'));

However I wouldn't make the primary key editable, this will lead to all sorts of problems down the track. What happens if you have foreign keys that are linked to this record, and then the administrator changes the primary key? Bad news.

I'd make the primary key an integer auto-increment field, and then have another field for user_code or similar. This will let you still have a user key that is editable, which won't affect your relations.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top