Update database upon clicking button

Hi! I’m new to yii.

One of the features i want to include is that each user can be a supporter of N projects (also each project can be supported by N users) such as in change.org

For example i have table user (uid, uname) and tbl project (pid, pname) as well as tbl user_project (id, uid (foreign key), pid (foreign key))

How do i add a ‘support project’ button to each project when i list all the projects as a user?

And when i click the button, tbl user_project will be populated with a serial id, my uid, and the pid of the project.

Sorry if im asking too much and cannot still provide more info

Are U going to use CGridView for listing projects or something else ?

Yes I’ll be using CGridView

Changes in _view.php

// generate url

<?php $urltmp=‘js:document.location.href="index.php?r=controller/action’; ?>

// code to display button on each list data

<div id="btn_display">

&lt;?php echo CHtml::Button (&quot;Add Comments&quot;,array('name'=&gt;'btn', 'target'=&gt;'_blank', 'onclick' =&gt; &quot;&#036;urltmp&quot;)); ?&gt;

</div>

Changes in controller.php

public function actionYouraction() //specify action what you have mentioned in the url

{


	&#036;model=new clasaName;





	if(isset(&#036;_POST['clasaName']))


	{


		&#036;model-&gt;attributes=&#036;_POST['clasaName'];


		if(&#33;empty(&#036;_GET)){


			// here I am setting values of attributes from url, change as per your needs


			&#036;model-&gt;setAttribute(&quot;column_name&quot;,Yii::app()-&gt;request-&gt;getParam('type'));	//set attribute values


			&#036;model-&gt;setAttribute(&quot;column_name&quot;,Yii::app()-&gt;request-&gt;getParam('id'));	//set attribute values


		}


		if(&#036;model-&gt;save()){


			&#036;this-&gt;redirect(array('view','id'=&gt;&#036;model-&gt;intId));


		}


	}





	&#036;this-&gt;render('view_for_redirection',array(


		'model'=&gt;&#036;model,


	));


}