Unable To Update Database

4733

view.php
Hello friends,

I am a newbie just started learning yii framework. I’ve created CRUD operations with yii but i want some extra functionality in my view.php of Association model. So I added some extra code in that to insert my textArea text into my database with submit button. This code works perfectly fine outside Yii framework application as i tested it with simple html file calling this same php excluding yii code from this file.

I am getting either of these bugs:

  1. If i change POST to GET, “Unidentified Index : $_POST[‘comments’]”

  2. If i keep as it is(current code), it does nothing, my database is not updated.

Any help will be much appreciated. Thanks in Advance.

Here is the code of my view.php file:

[color="#006400"]/* Moved from "Bug Discussions" to "General Discussion for Yii 1.1.x" */[/color]

Hi Pratik, welcome to the forum.

You would be better learn how to code with MVC "framework" first.

http://www.yiiframework.com/doc/guide/1.1/en/basics.mvc

http://www.yiiframework.com/doc/guide/1.1/en/basics.best-practices

Hi softark,

Thank you for your quick response.

Surely I’ll go through the basics of MVC, thanks again for the links.

So is that i cannot access the GET and POST variables with the Views ? Shall i access those with the Controllers instead ?

I got the Idea such as I can put SQL statements and some logic in Model, I can access it through controllers and present in Views. But not sure how so If you can just give me a hint or example of how I shall run that simple PHP script if i wanted to with MVC ( yii framework ) that would be great.

Thanks a lot,

Pratik Mehta

Yes, you should.

In fact you can access GET and POST in view, but you would be better not. :)

Yes, you are right.

Please take a close look at "create" and "update" actions of gii-generated CRUDs. Examine how Model, View and Controller work together in them. They will show you how to insert/update a database record using Yii framework.

It may look overdoing for a simple task, especially when you have good experience in plain PHP programming. But it will surely help you a lot when things get larger.

Another thing you might not like at first might be AR (Active Record). But I’m sure you will love it in the end. :)

Hi Softark,

Thanks a lot for taking time in explaining me the whole concept. The links were pretty good and hopefully i can learn in no time. Much appreciated. :)