I'm starting a new application using Yii, and I have a Database with a table called Rules, so, using the Yii shell, I generated the model, and crud operations for Rules.
The problem is that, just by doing this… I should be able to work with it, but when I try to create a "Rule" in Rules, the app let me fill all values in the textfields, but after that, it throws a "Internal Server Error". This error is because after executing the $rules->save(), which returns a 1 (true), application try to show() the recently added record, but it doesn't exists in database.
If I fill the database by hand, I can make updates to any record, but as I said, I cannot create new ones. Also, I have another tables in system, and they work fine with crud operations.
Hope anyone can help me.
So you modified rules() method and the create action no longer works? What did you modify? Could you show the code?
No, I did not make modifications to rules()… For isolate the problem, I started again in a new project, build the same database, and from scratch started with model Rules, and crud Rules from the yii shell. And when I try to create a new one, have the exact same problem…
Actually, the complete error message is this:
Internal Server Error
The requested rules does not exist.
An internal error occurred while the Web server was processing your request. Please contact the webmaster to report this problem.
The funny thing is that, when the save() method is executed, inside RulesController->actionCreate(), it shows that no error is present, by returning a '1', but it doesn't make changes in database.
I'm using sqlite, and this is the DB create script for that table:
CREATE TABLE Rules
idRule INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
alignment INTEGER NOT NULL,
protocol VARCHAR(10) NOT NULL,
source VARCHAR(18) NOT NULL,
sourcePort INTEGER NOT NULL,
destination VARCHAR(18) NOT NULL,
destinationPort INTEGER NOT NULL,
interface VARCHAR(20) NOT NULL,
chain VARCHAR(7) NOT NULL,
idAction INTEGER NOT NULL,
option VARCHAR(40) NOT NULL,
comment VARCHAR(128) NOT NULL
Maybe "Rules" is some kind of reserved word or something like that…
Thanks in advance,
This is because your model class is named as Rules, and CActiveRecord has a method named 'rules'. The latter is treated as the constructor of Rules (PHP 4 syntax). In this sense, yes, rules and other method names in CActiveRecord should not be used as class names.
Thank you very much. Actually, I changed the name of the table, and everything works just fine.