I would like to create a button that can be used to populate a table in my db with a single click.
I am just not sure what I need to do here to make this happen. Can I assign a method to be executed by a button? Or just have values picked up in my controller? Below is something like what I want to execute but through a button.
public function addInterest($interest)
{
$interest->UserId=Yii::app()->user->id;
$interest->ItemId=$this->ItemId;
return $interest->save();
}
Can someone point me in the right direction on what I should be looking at doing?
The button is going to have to either submit a form or a get request. I’d just write it in JQuery and push the request up to a controller/action using .get().
Packing your addInterest method invoking into action will be needed. I am not sure what class this method is member of - assuming controller, in the action method you need to create object of Interest type and invoke addInterest method.
For adding button you can use ajax or regular style. In the latter case create simple form contains only submit button. For ajax use CHtml::ajaxButton(). In both cases use created action as a target.