Welcome Guest, Not a member yet? Register   Sign In
Calling controllers from controllers
#1

[eluser]Iverson[/eluser]
I know a lot of people are against this idea and libraries that do it ie. Wick. I think it's of great use but I can understand the complaint, so I'm looking for others' ideas on how to make what I wanna do work. I have a bunch of different controllers. Quite a few of them need to send out notifications. A bunch of the controllers' methods will need to send out the same notification. It would be great to have one controller that handled sending emails. Naturally I don't want to have to add all the email functions in all those different controllers. Ideas?
#2

[eluser]Colin Williams[/eluser]
It's really a matter of how CI was designed. A Controller is just an instance of CodeIgniter class. So, to have other controllers available to call, you need multiple instances of the entire CodeIgniter class.

Code:
include(APPPATH.'controllers/notice.php');
$this->notice = new Notice();
$this->notice->method_to_call();

What is wrong with having a library send out these notices for you? Or even a helper.

Code:
send_notices($users, $vars, $template);

If notices aren't an application resource, I don't see the need for having a Controller for them.
#3

[eluser]Iverson[/eluser]
[quote author="Colin Williams" date="1239404496"]It's really a matter of how CI was designed. A Controller is just an instance of CodeIgniter class. So, to have other controllers available to call, you need multiple instances of the entire CodeIgniter class.

Code:
lnclude(APPPATH.'controllers/notice.php');
$this->notice = new Notice();
$this->notice->method_to_call();

What is wrong with having a library send out these notices for you? Or even a helper.

Code:
send_notices($users, $vars, $template);

If notices aren't an application resource, I don't see the need for having a Controller for them.[/quote]

Good idea. I'll probably just make a lib and each notification will have a method. Anything theoretically wrong with accessing models in a library? Btw, EE killed the beginning of your code Smile
#4

[eluser]Colin Williams[/eluser]
Quote:Anything theoretically wrong with accessing models in a library?

It seems a bit messy but if it makes the most sense, it makes the most sense... But, usually when I'm writing a library and realize I'm doing a lot of db calls or wanting to access models, then the library should really just be a model, or part of the model it's trying to access.
#5

[eluser]wiredesignz[/eluser]
[quote author="Colin Williams" date="1239404496"]It's really a matter of how CI was designed. A Controller is just an instance of CodeIgniter class. So, to have other controllers available to call, you need multiple instances of the entire CodeIgniter class.
[/quote]

FYI, Modular Extensions as of versions 5.2 and 4.3 use a single CI application instance and seperate controller instances for module controllers as needed.




Theme © iAndrew 2016 - Forum software by © MyBB