CodeIgniter: Load controller within controller

后端 未结 10 1733
余生分开走
余生分开走 2020-11-28 07:43

I have a home controller with an index action that displays a set of featured products. However, the products are managed through a product

10条回答
  •  遥遥无期
    2020-11-28 08:42

    If you're interested, there's a well-established package out there that you can add to your Codeigniter project that will handle this:

    https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/

    Modular Extensions makes the CodeIgniter PHP framework modular. Modules are groups of independent components, typically model, controller and view, arranged in an application modules sub-directory, that can be dropped into other CodeIgniter applications.

    OK, so the big change is that now you'd be using a modular structure - but to me this is desirable. I have used CI for about 3 years now, and can't imagine life without Modular Extensions.

    Now, here's the part that deals with directly calling controllers for rendering view partials:

    // Using a Module as a view partial from within a view is as easy as writing:
    
    

    That's all there is to it. I typically use this for loading little "widgets" like:

    • Event calendars
    • List of latest news articles
    • Newsletter signup forms
    • Polls

    Typically I build a "widget" controller for each module and use it only for this purpose.

    Your question was also one of my first questions when I started with Codeigniter. I hope this helps you out, even though it may be a bit more than you were looking for. I've been using MX ever since and haven't looked back.

    Make sure to read the docs and check out the multitude of information regarding this package on the Codeigniter forums. Enjoy!

提交回复
热议问题