CodeIgniter Forums
Call a controller function from another controller and pass that as 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: Call a controller function from another controller and pass that as view (/showthread.php?tid=42658)



Call a controller function from another controller and pass that as view - El Forum - 06-14-2011

[eluser]Paleleaves[/eluser]
Hi,

I found something similar topics in the forum but my question is somewhat different.

Code:
$data["login_screen"] = $this->load->view("auth/login", "", TRUE);

// 'auth' is my controller name and 'login' is a function inside that. I've the above statement in a different controller.

  $this->load->view('notlogin', $data);

And i tried to echo $login_screen in my view file it returns an error that login.php not found. 'login' is actually a controller function not the file name. Is it possible to pass function name as view file?

please advise..


Call a controller function from another controller and pass that as view - El Forum - 06-14-2011

[eluser]danmontgomery[/eluser]
Nope, you can't call one controller from another. This breaks the MVC convention. You would have to use a modular solution like https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home or https://bitbucket.org/wanwizard/modular-ci/

With those solutions, you're still not going to be able to exactly what you're trying, since controller methods aren't views. But, you can call methods from other controllers and pass that data into a view.


Call a controller function from another controller and pass that as view - El Forum - 06-14-2011

[eluser]Paleleaves[/eluser]
Thanks noctrum!

I've been fooled around this issue for sometime! Thank you very much for the info.