I have the following button:
<?php $this->widget('bootstrap.widgets.TbButton', array(
'label'=>'myLabel',
'buttonType'=>'ajaxButton',
'url'=>'someUrl',
'type'=>'primary', // null, 'primary', 'info', 'success', 'warning', 'danger' or 'inverse'
'size'=>'small', // null, 'large', 'small' or 'mini'
'ajaxOptions'=>array(
'type' => 'POST',
'beforeSend' => '
function( request ) {
//alert(request);
}'
,
'success' => 'function( data ) {
//alert(data);
}'
,
'data' => array(
'actionName' => "INCREMENT"
)
),
)); ?>
So, the tricky part is, how do I connect this button to actual backend code? I would assume it’s done by posting to a URL. In my case I’ve got a URL set as:
'url'=>'someUrl'
Does this mean I must create a view, controller and model so there is a URL to post to? isn’t there an easier way without going through that effort?
You do not necessarily need a new view. But you will need an action that catches this request.
In Yii each action has a unique url that refers to it, and there are functions that generate such a url for us, namely
createUrl. There are other versions ofcreateUrlalso, the one here is fromCController.So you’d modify your url property as:
Then in your controller add the action: