Hello guys,
I want to write a jquery code in mycontroller/Show,like this;
public function Show(){
<script>
jQuery("#block").animate( { width: "100%","opacity": "show"}, { queue: false, duration: 2000 });
</script>
}
and then call this function in mycontroller/actionIndex like this;
public function actionIndex(){
mycontroller;:show();
}
anyone suggest me how I can do better this? It is necessary to use this method in controller…
You are mixing server side code (PHP) with client side code (JS).
You could use a php variable to pass from action’s controller to
view’s controller, as a flag.
For example:
Controller:
function actionIndex()
{
$activateShow = true;
$this->render('Show', array('activateShow' => $activateShow));
}
View:
<?php if ($activateShow) { ?>
<?php Yii::app()->clientScript->registerScript('js_show', '
jQuery("#block").animate( { width: "100%","opacity": "show"}, { queue: false, duration: 2000 });
<?php '); ?>
<?php } ?>
So when $activateShow is true, the js code will be inserted in view.
Hello Dear Friend,
I can’t use render method because when actionIndex() call , it si redirect to another site… so meantime I want to show animiton bar,
Please can you specify me where I can register this function
and then I want to call this function in my mycontroller actionIndex. if you can this,
I am using this method in my controller actionIndex
but get this error
. Where I can put my function and then call into my controller.thanks in advance.