• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Send value from view to method and vice versa

#1
Hi!

I need send value from view to function in controller and return to view.
Example on code:

VIEW:
PHP Code:
echo 'Count: ' AddNumber(2); 

CONTROLLER:
PHP Code:
function AddNumber($value) {
 
  $NewValue $value*2;
 
       
   
return $NewValue// = 4, pass this to view again in the same place

Reply

#2
(09-11-2015, 12:57 PM)vertisan Wrote: Hi!

I need send value from view to function in controller and return to view.
Example on code:

VIEW:

PHP Code:
echo 'Count: ' AddNumber(2); 

CONTROLLER:

PHP Code:
function AddNumber($value) {
 
  $NewValue $value*2;
 
       
   
return $NewValue// = 4, pass this to view again in the same place


In this case a helper function is the best choice.

Reply

#3
Hi,
If you want to send a value to your controller, you are many ways switch your problem. Here, we don't know if you want t send a vlue when you click on a button (picture, etc.) or when a time is elapsed, etc..
A controller is to manage your wiew and call models.
If you don't need to do that and simply modify a value without using models, a simply helper or library is sufficient.
Reply

#4
I think you need AJAX to do this.
Insert a link to the latest Jquery library in the 'head' section of your view (or template).
Jquery makes life a lot easier when it comes to implementing AJAX.

At the bottom of your view, create a script that sends an AJAX-request to the controller (with the current value), and get the new value back.
Jquery can replace the old value by the new value on the fly.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.