• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
communication between controllers

#1
Hi!

I have an input controller (api) and it has to communicate with different controllers as needed, for example, users, products. Currently one controller calls another through CURL, what is the best way to communicate with each other?

The project is in Codeigniter 3

Best Regards
Reply

#2
normeno,  normally you want to make your controllers pretty light (ie on actual source code/biz logic) and then create a library for the heavy lifting. That way any controller can talk to those libraries in any other controller.

You can have
Code:
$user = $this->user->get_current();
and
Code:
$this->product->get_by_id($product_id);


Also depending on what you are trying to do when working with data object's the model might be the best "shared" place for your code.
Code:
$product = $this->product_model->by_id($product_id);


Hope this helps.

Then you don't need to call controllers from controllers...

DMyers
Reply

#3
A request should route through a single controller. In MVC controllers should not cross talk.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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