CRUD not working

Hi,

after installing gii (according to blog and other tutorials), CRUD doesn’t seem to work. Doesn’t matter what I fill in the create/update forms, after submitting the form nothing happens (no error message, same page, no changes in db). The only thing that works is delete function.

Any suggestions?

Some more info -

It doesn’t seem to have anything to do with privileges. Adding a simple mysql_connect(…), mysql_select_db(…), mysql_query(INSERT…) in to controller adds values to database. The last query in the log is SHOW CREATE TABLE blog in a green background, so it seems to be working.

Really frustrated, as it is one of the first steps in learning yii, and it doesn’t work.

maybe you can try to put


var_dump($model->getErrors());die();

after the


$model->save();

line in your controller file(create, update function). See whether there are errors or not.

Btw, do you add some function like beforeSave() in the model? If you do, check whether it has return or not. I ever got similar case with you, that’s because I forgot to add the “return parent::beforeSave()”

Thanks for the reply. Tried your suggestion and it seems that


if(isset($_POST['blog']))

is not set. I manually added


<input type="hidden" name="blog" value="1" />

to the view _form (just for a quick test), and now it says that all the fields are blank. So the problem lies somewhere else.

Oh, and array of errors is empty. And I haven’t modified anything in a controller yet.

Solved!


	if(isset($_POST['blog']))

		{

			

			$model->attributes=$_POST['blog'];

In my case, blog was supposed to be Blog…

Perhaps the tutorial is not right or something has changed, but a code generated by gii lowercased the model name. Well, if the naming convention says that model should start lowercase, then the tutorial is wrong.

By default in Gii in Model generator… as you enter table name in "lowercase"

in the Model Class (second line) the name is copied as first char uppercase…

ie. you enter "blog" in table name… and in "model class" you get Blog…

Could it be that you modified that and typed lowercase?

No, I didn’t. The thing is, that model name is still Blog (as I understand from this code):


class Blog extends CActiveRecord

{

	/**

	 * Returns the static model of the specified AR class.

	 * @return Blog the static model class

	 */

	public static function model($className=__CLASS__)

	{

		return parent::model($className);

	}

And in the form, I get generated


name="Blog[title]"

etc. But the controller expects an array named blog, not Blog.

Now I tried generating new CRUD controllers, first inserting blog, then Blog, and although it says the Model Class is case-sensitive, both times it generated same thing (although there is no model called blog) with a $_POST[blog] in controller.

It’s strange, because Gii checks if the models exists…

I just tried to enter a model in lowercase (Gii-CRUD generator) and when I press Generate I get the error - Class ‘kontakt’ does not exist or has syntax error. (kontakt is my table and Kontakt is the model)

So makes me think that you have two models "Blog" and "blog" - check your model directory

If it does not help please try all from the begining - create a new webapp (ie. yiitest) and try there to make this working…

There is only Blog in my models directory.

Tried a new app. Same thing. Pic

Only clicked preview.

Any suggestions what may cause this? As apparently this is bug. If you need any info about my environment - just ask.

It’s becasue of windows that treats User.php and user.php equal while linux does not…

In CRUD generator you should type the model name with first letter uppercase…

anyway

Qiang already added a check for this… so in the next release Gii will display an error for this even on windows…