CodeIgniter: Load controller within controller

后端 未结 10 1752
余生分开走
余生分开走 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:24

    Based on @Joaquin Astelarra response, I have managed to write this little helper named load_controller_helper.php:

    $method();
        }
    }
    

    You can use/call it like this:

    $this->load->helper('load_controller');
    load_controller('homepage', 'not_found');
    

    Note: The second argument is not mandatory, as it will run the method named index, like CodeIgniter would.

    Now you will be able to load a controller inside another controller without using HMVC.

    Later Edit: Be aware that this method might have unexpected results. Always test it!

提交回复
热议问题