How to refresh the view on a button click

Hi,

I’ve tried coding the options of CHtml::button in many many different ways, so that when I click on it, the current view would be refreshed, but I couldn’t succeed, so I’m asking for some help…

I’m using Yii 1.1.5.

Here is the last code I’ve tried with no success :


<?php echo CHtml::button('Réinitialiser', array('clientChange', array('click' => CController->refresh()))); ?>

Thanks in advance…

you can load content via ajax, or you can make refresh whole page. check window.location.reload

Actually I wanted to use the Yii refresh function because the effect of this method call is the same as user pressing the refresh button on the browser (without post data).

With window.location.reload the post data is sent along…

Hello ‘cher compatriote’

You can’t call a serverside method directly from clientside… the ‘click’ action on a button is a javascript client side event, and won’t raise a server side one (except in case of form post)

The easier for me is to put a link (not a button), with the current url (Yii::app()->getRequest()->getUrl()), or, if you really want a button, use a javascript onClick event to set window.location to the current url




echo CHtml::htmlButton ('Refresh', array('onClick'=>'window.location="'.Yii::app()->getRequest()->getUrl().'"'));



Hi ‘voisin’ (I’m in Nice ;) ),

well thanks for your answer, it works. I can even replace htmlButton with Button, it works as well. Actually, according to the Yii documentation, you can use clientChange with Button, and with clientChange you can use javascript events. That’s what I was trying to do…

No, clientchange can’t be use to attach event handler.

Look at its documentation, and the source code… With theses options, you can change the submit url, or add a “confirm”, or change the return value of the default ‘onclick’ event, but you can’t change the event itself.

You can only do that with classic ‘onclick’ html attribute, or by attaching your own event handler with some jQuery.

I used htmlButton instead of button, because the former will render a <button>, which is, imho, better than <input type=“submit”> when there’s no form submission…