Module load breaks view load (old code)

筅森魡賤 提交于 2019-12-12 01:46:47

问题


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:


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, $...); ?>



来源:https://stackoverflow.com/questions/10462377/module-load-breaks-view-load-old-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!