CodeIgniter Forums
Load function, not view - 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: Load function, not view (/showthread.php?tid=4295)



Load function, not view - El Forum - 11-16-2007

[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


Load function, not view - El Forum - 11-16-2007

[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);


Load function, not view - El Forum - 11-16-2007

[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?


Load function, not view - El Forum - 11-16-2007

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


Load function, not view - El Forum - 11-16-2007

[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


Load function, not view - El Forum - 11-17-2007

[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!