codeigniter+HMVC cross module call controller->method

前端 未结 7 1135
有刺的猬
有刺的猬 2020-12-16 01:32

I am pulling all my hair off... Have been searching every thread, would appreciate if someone can point me to a working example.

Accroding to the doc: https://bitbuc

7条回答
  •  南笙
    南笙 (楼主)
    2020-12-16 02:18

    Thanks for MC's tip, I finally figured out the cause. HMVC doc indeed lacks some examples for beginner.

    For anyone who may find this thread in the future, correct usage here:

    to call module01/controller01/method00:
    
    //method 1 CORRECT:
    $ctlObj = modules::load('module01/controller01/');
    $ctlObj->method00();
    //or you could use chaining:
    modules::load('module01/controller01/')->method00();
    
    //method 1 WRONG:
    modules::load('module01/controller01/method00');  //this will only load contructor
    
    ---
    //method 2 CORRECT:
    modules::run('module01/controller01/method00');   //no trailing slash!
    
    //method 2 WRONG:
    modules::run('module01/controller01/method00/');  
    
    ---
    //method 3 CORRECT:
    $this->load->module('module01/controller01');
    $this->controller01->method00();
    

    I don't understand why method 3 failed when I first try... maybe because I restarted HTTPD?

提交回复
热议问题