making a responsive Widget (counting)


I want to create a widget to control some values in my web UI. My usecase is complex, so I’ll only want to show the problems which I cant fix.

Lets think about a small widget: a button("+"), a text field and a button ("-").

I want a widget, that transforms the input (some number) to an output (some new number) by clicking this buttons.

So here is my view (located under components/view/counter.php):


    <?php echo CHtml::Image(CHtml::asset(Yii::getPathOfAlias('webroot.images.up').'.png', '+')); ?>


    <?php echo CHtml::textField('counter', $this->counter); ?>


    <?php echo CHtml::Image(CHtml::asset(Yii::getPathOfAlias('webroot.images.down').'.png', '-')); ?>


…and my controller (located under components/counter.php):


class Counter extends CWidget


    public $pickcount;

    private $counter;

    public function getCounter(){return $this->counter;}

    public function raiseCounter(){

        $this->counter = $this->counter + 1;



    public function lowerCounter(){

        $this->counter = $this->counter - 1;






    public function init()


        //... some string actions, don't mind everything is good, keep it simple $pickcount is the result ...

                $this->counter =  $this->pickcount


    private function checkConsitency()


	//... does fancy things, don't mind everything is good...


    public function run()




        $this->pickcount = 'WOOWs to the solution: ' . $this->counter;

        //return HTML::encode($this->pickcount);




…all this is called like:

    <?php $this->widget('Counter',array('pickcount'=>$one)); ?>

    <?php $this->widget('Counter',array('pickcount'=>$two)); ?>

    <?php $this->widget('Counter',array('pickcount'=>$three)); ?>

…so how can I connect the view to the controllers raiseCounter and lowerCounter functions, rerender the view and get the values back to $one, $two and $three

Please help me or give me a hint.

Is this so wired that nobody has a hint to solve this?

Or any suggestion for a workaround?