• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Call a controller function from another controller and pass that as view


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

$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..

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/codeig.../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.

Thanks noctrum!

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

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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