• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Load function, not view

#1
[eluser]RobbieL[/eluser]
At the end of a controller, instead of loading a view, is it possible to load a function? I know you can redirect to a function, but that doesn't allow you to carry $data ... does it?

Cheers.
RobbieL

#2
[eluser]gtech[/eluser]
yes you can load a function, if the functions in the same controller, you dont have to load a view at all.

$this->functionname($param1,$param2);

#3
[eluser]RobbieL[/eluser]
Ah, excellent.

I've got another related problem. I want to pass a varible to the function I'm going to be loading. So I place it where you've put $param1.

I gather I have to then, in the function I'm loading, put function index($param1). When I do that, I get an spit up on my page regarding that parameter.

Any ideas?

#4
[eluser]RobbieL[/eluser]
Oh, think I got it. Had to set the parameter in the index function to be FALSE by default.

#5
[eluser]gtech[/eluser]
Code:
<?php
class Test extends Controller {
  function test() {
    parent::Controller();
  }
  function fish($var1="Nobody") {
    $var2 = "likes fish";
    $this->anotherfunc($var1,$var2);
  }
  function anotherfunc($var1,$var2)
  {  
    echo $var1." ".$var2;
  }
}
?>

Not sure I understand your question so I shall do a quick example see above..
it defaults to "Nobody likes fish"

if you call it with:

http://localhost/......./index.php/test/fish/Wilma

it will display "Wilma likes fish"

[edit]sorry missed your reply, glad you got it working

#6
[eluser]RobbieL[/eluser]
Cheers gtech, that actually helped a great deal. My problem was I was trying to pass two parameters to my Index function, by in the function they were being passed from only one of the variables was actually being declared.

Thanks again!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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