Yii Framework Forum: I Want To Write A Jquery Code In Mycontroller - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

I Want To Write A Jquery Code In Mycontroller I want to write a jquery code in mycontroller.php file Rate Topic: ***** 1 Votes

#1 User is offline   Muhammad Shahzad 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 29-January 13
  • Location:Islamabad,Pakistan

Posted 26 April 2013 - 12:34 AM

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..
0

#2 User is offline   Fabrizio Caldarelli 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 336
  • Joined: 21-March 13
  • Location:Rome, Italy

Posted 26 April 2013 - 01:59 AM

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.
1

#3 User is offline   Muhammad Shahzad 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 29-January 13
  • Location:Islamabad,Pakistan

Posted 28 April 2013 - 02:37 PM

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

Quote

<?php

Yii::app()->clientScript->registerScript('show_animition_bar', "


$({someValue: 0}).animate({someValue: 100}, {
duration: 2000,// 2 second
step: function() { // called on every step

$('#block').text('Processing...'+Math.floor(this.someValue+1)+'%');
$('#block').animate( { width:'100%','opacity': 'show'}, { queue: false, duration: 2000 });
},
complete : function(){
$('#block').text('Processing Complete!');
}
});


", CClientScript::POS_READY);


?>


Quote

<div class="progress_bar_test" id="block">



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

Quote

Yii::app()->getClientScript()->scripts['show_animition_bar'];

but get this error

Quote

Undefined index: show_animition_bar
. Where I can put my function and then call into my controller.thanks in advance.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users