widget and renderpartial?

I have a problem around rendering a widget with ajax.

A concrete example. It’s a webshop. I want a little widget into a corner to show the basket summary.(ex: $15.30 ).

This widget should be on the main layout.

But it needs to be updated with ajax also because the ‘put the items to the basket’ link is also an ajaxlink.

I hope you understand what I want to do and you can help me.



I have a similar problem but not the same. I’m using the gridview widget, and i’d like to use render partial (like render the update form on the same page filled with the proper data), if i could have the id from that point it wont be a problem at all i guess =)

<?php $this->widget('zii.widgets.grid.CGridView', array(























)); ?>

but i can not get there the id. if im seeing the source, i got this:

jQuery('#yt1').click(function(){jQuery.ajax({'url':'/index.php?r=update&id=projecten','dataType':'html','type':'POST','cache':false,'data':jQuery(this).parents("form").serialize(),'success':function(html){jQuery("dataform").html(html)}});return false;});

somebody has an idea whats happening with the $data variable, why cant i retrieve the information from it?


i think you need to use partial views for that little ‘basket’ like need to define an action in your controller which update that basket(div, span, etc.), and also u need to define the ajax options for your link like this:

your view should look like this:


<tr><td>product info</td><td><?php

    echo CHtml::ajaxLink('ajaxbutton',


		array (

			'type' =>'POST',

			'update' => '#basket',

                        'data' => $product_id



			     'class' => 'btn_basket',

			     'title' => 'put into basket',

			     'id' => 'ajaxlink'.$i,





for your controller you need toi define an action like this

public funcion actionPutIntoBasket(){


retrieving the product info from the id


echo $new_basket_content;


and also you need to have a div or span or something what you update

<div id="basket">



i think that should do ;)

Thanks it was clear for me, but how can I initialize this ‘little basket’ in the main layout?

I want to init it at ‘body onLoad’.

Any suggestion?

There must be an action in your controller which handles the stuff when the "main layout" can be seen. In this action you have to also have to return the basket data as well.



	'data1' => $data1,

	'basketdata' => $basketdata,


and in your view you can render it in the first time as a partial view:

<div id="basket">

    $this->renderPartial('_basket', $basketdata);


if i got ur problem right

and this would be initialized at the very first time when your page loaded in your main layout.

Thanks I think it’ll be ok for me.

I know it’s an old topic, but I had the same problem, for some reason there is no renderPartial method in the widget class. So I copied the renderPartial method from /framework/web/CController.php into my Widget class and everything worked perfectly. Maybe there are better solutions, but for me this was good enough.

it a little rough…

but u could just add function renderPartial in your widget

    public function renderPartial($view,$data=null,$return=false,$processOutput=false)


        $this->controller->renderPartial($view, $data, $return,$processOutput);


Hello guys!

I have solved this in a very simple way.

I posted the full explanation on another post in the yii forum.




I have done according Andreas post. But it make my boostrap.min.js do not work. do u know why? ???

i have spent 5 hours to fix it but still no way out. Any help pls…?