CodeIgniter Forums
Calling Controllers Functions with function name in a php variable - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Calling Controllers Functions with function name in a php variable (/showthread.php?tid=4512)



Calling Controllers Functions with function name in a php variable - El Forum - 11-29-2007

[eluser]ReSTe[/eluser]
Hi all...

I've a problem:

i have a variable named backpergest2 that contains the name of a function of my controller.
The idea is that i'm in a controller function and i've to call another controller function (backpergest2=name of controller function that i've to call)...

i've tried this code:

$this->$backpergest2;

but php shows me the following error:

Severity: Notice

Message: Undefined property: Tmfmagenta::$visualizzaprocspec()

Filename: controllers/tmfmagenta.php

Line Number: 18103


as u can see the name of the function that i've to call is visualizzaprocspec() and it is also the content of the variable $backpergest2.

what can i do?

thanks a lot, and greetings from italy Smile

Matteo

PS: the function visualizzaprocspec() exist in the controller.


Calling Controllers Functions with function name in a php variable - El Forum - 11-29-2007

[eluser]gtech[/eluser]
I tried somthing similar as a test for you and it worked.. create a controller called test.php copy the code and give it a go!
Code:
<?php
class Test extends Controller {

  function Test()
  {
    parent::Controller();
  }
  function start($func='myname')
  {
    echo "hello";
    $this->$func();
  }
  function myname()
  {
    echo " gtech";
  }
}
?>

result
Code:
hello gtech

Or are you trying to do something different? you may just have a typo (typing error) somewhere.


Calling Controllers Functions with function name in a php variable - El Forum - 11-29-2007

[eluser]ReSTe[/eluser]
yeah it works!!!

wonderful Smile

my error was in the content of the variable

bad variable: $var="visualizzaprocspec()"

right variable: $var="visualizzaprocspec"

stupid "()" Big Grin Big Grin Big Grin

thanks a lot u have helped me with my thesis.

thanksthanksthanks

Matteo.


Calling Controllers Functions with function name in a php variable - El Forum - 11-29-2007

[eluser]gtech[/eluser]
cool, glad to of helped.