dpevsxjn809817 2012-05-05 13:35
浏览 16
已采纳

模块加载中断视图加载(旧代码)

I'm trying out codeIgniter and the Modular Extension. So far I followed the installation instructions from wiredesignz on bitbucket. Now I'm trying the tutorial HMVC: an Introduction and Application from NetTuts.

I'm doing this with the actual version of CodeIgniter 2.1 and the actual version of the Modular Extension (downloaded the .zip version from bitbucket).

All works fine until I'm trying to run a method from a controller of another module.

The setup in short is, that there's two modules (site & login). Within the site's controllers there's site.php (/modules/site/controllers/site.php) with a method that checks if a user is logged in. This method would exit the script execution if accessing the site without being logged in. As this method logically belongs to the login module, the author suggests moving it there. So it then is moved to /modules/login/controllers/login.php.

The problem now is, how to access the method of the login module from within the site module. The slightly adjusted code from the tutorial:

// modules/site/controllers/site.php

function __construct()  
{  
    // parent::Controller();
    // replaced with:
    parent::__construct();

    // modules::run('login/is_logged_in');
    // replaces with:
    $this->load->module('login')->is_logged_in();
}  

Like this I'm getting an error:

Unable to load the requested file: logged_in_area.php

The method in question is inside the site module as well:

// modules/site/controllers/site.php

function members_area()
{
$this->load->view('logged_in_area');
}

The Script executes right until the load->view line and produces the error. There's no problem accessing the logged_in_area.php with running the is_logged_in method from within the site controller with the line:

$this->is_logged_in();

Any ideas?

edit:

the application tree:

/application
  /...
  /modules
    /login
      /controllers
        login.php
      /models
      /views
        login_form.php
        signup_form.php
        signup_successful.php
    /site
      /controllers
        site.php
      /models
        membership_model.php
      /views
        logged_in_area.php

PS: How can I get more INformation about the error? CodeIgniter seems to be very reserved about error output ...

  • 写回答

1条回答 默认 最新

  • dongxia5394 2012-05-06 18:17
    关注

    As stated in the documentation here to load a view from within another module, you need to use an extended MX controller and a method:

    <?php echo Modules::run('module/controller/method', $param, $...); ?>

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题