Codeigniter : calling a method of one controller from other

后端 未结 10 1944
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-05 01:48

I have two controllers a and b.

I would like to call a method of controller a from a method of controller b.

10条回答
  •  生来不讨喜
    2020-12-05 02:41

    I posted a somewhat similar question a while back, but regarding a model on CI.

    Returning two separate query results within a model function

    Although your question is not exactly the same, I believe the solution follows the same principle: if you're proposing to do what you mention in your question, there may be something wrong in the way you're coding and some refactoring could be in order.

    The take home message is that what you're asking is not the way to go when working with MVC.

    The best practice is to either use a Model to place reusable functions and call them in a controller that outputs the data through a view -- or even better use helpers or libraries (for functions that may be needed repeatedly).

提交回复
热议问题