Complete yii newbie here, but I’ve gone through the documentation I could find and searched the forum for crud related things and didnt find an answer, so here goes:
I downloaded, installed and configured yii 1.1.0.r1700.
However, when I now visit http://bla.com/index.php?r=employee/create i’m only allowed to enter ‘pass’. If I enter something into the pass field and click create, I get an error:
Please fix the following input errors:
Name cannot be blank.
Clearly, the model is correct, only the generated crud is wrong…
When I look at the generated _form.php, it also only lists the pass field, but not the name field:
The ‘name’ field is not created in the form, because it is a primary key (I think). In most cases you will have the DB or application to deal with the primary key.
Just add an id column whether you need it or not. Set the id column to be the primary key (not null and autoincrement). Regenerate your model, then regenerate your crud.
Thank you for all the replies! So actually, it appears this is working as intended because crud is assuming i have an autoincrement id field when I don’t? Thats not a good assumption and I’d consider that a bug, crud could check for that and act accordingly…
Since I’m just starting out I’ll give the 1.1.1 version a try and install iCRUD.
Else I’ll add it manually as you guys suggested (though I was hoping to use crud to prevent exactly that )
I agree that perhaps the crud shouldn’t make assumptions about the primary key like that.
I recently had the same problem with a country table where I wanted to use the (ISO 3166-1 alpha-2) 2 letter country codes as the primary key, since they are natively unique anyway.
For ease of use I ended up adding a redundant ID field in the same way, but it is just that - redundant.
A simple check to see if the primary key is auto-incremented before generating the appropriate code would probably be all that is needed.