Dumped $this->load inside module:
CI_Loader Object
(
[_ci_ob_level] => 0
[_ci_view_path] => ../app/views/
...This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
March 03, 2008 6:10pm
Subscribe [48]#451 / Jun 05, 2008 5:20am
Dumped $this->load inside module:
CI_Loader Object
(
[_ci_ob_level] => 0
[_ci_view_path] => ../app/views/
...#452 / Jun 05, 2008 5:28am
Also tried to load it via module helper from another controller:
$this->load->helper('modules');
echo modules::run('files', array(), '', true);same result.
#453 / Jun 05, 2008 5:43am
Tried parent::__construct() but it doesn’t helped.
btw, I’m trying to launch module directly with http://localhost/files/.
Assuming from the above that your CI installation is in doc root and you are using .htaccess to remove index.php
You do not need to load the modules_helper it is loaded automatically.
modules_helper.php is located in application/helpers
Controller.php and MY_Router.php are both in application/libraries
Your controller is application/modules/files/controllers/files.php
and your view is application/modules/files/views/list.php
It will work.
#454 / Jun 05, 2008 5:55am
No, my installation is outside docroot:
app/
modules/
www/
index.phpAnd I’m using .htaccess.
Just tested with fresh CI 1.6.2. Works.
Tried with fresh CI outside docroot… works.
Tried with post 1.6.2 SVN… works.
Just found what faied… it’s MY_Controller I’m using for access control.
<?php if (!defined('BASEPATH')) exit('No direct access allowed.');
// Controllers accessible by everyone, regardless of login status
class Public_Controller extends Controller {
/**
* @var CI_Loader
*/
public $load;
/**
* @var CI_Benchmark
*/
public $benchmark;
function Public_Controller() {
parent::__construct();
//for debug
//$this->output->enable_profiler(TRUE);
// Get the user data, in case they are logged in
$this->data->user = $this->auth->get_user($this->session->userdata('user_id'));
}
// This function is used to prevent a user from accessing a method if they are logged in
function no_user_access() {
if ($this->data->user !== FALSE) {
redirect('');
}
}
function restrict_access(){
if(!isset($this->data->user->id)){
redirect();
}
}
}
// Controllers only accessible by logged in users
class Auth_Controller extends Public_Controller {
function Auth_Controller() {
parent::__construct();
if ($this->data->user === FALSE) {
// The user is not logged in, send them to the homepage
redirect('');
}
}
}
// Controllers only accessible to logged in users that are admins
class Admin_Controller extends Public_Controller {
function Admin_Controller() {
parent::__construct();
if (($this->data->user === FALSE) || ($this->data->user->role != 'admin')) {
redirect('');
}
}
}#455 / Jun 05, 2008 5:57am
Sam, the method is parent::Controller() not parent::__construct() Version 4.1 Controller class has no __construct() method and errors on my PHP5 installation.
#456 / Jun 05, 2008 5:58am
That’s the same in PHP5.
#457 / Jun 05, 2008 6:04am
Stripped everything from MY_Controller so it’s just blank. Is seems existance of this empty file prevents HMVC to work properly.
#458 / Jun 05, 2008 6:26am
Using Modular Extension makes using MY_Controller obsolete, you can autoload and run any controller before your main controller. Any auth or setup can be done in the autoload controller.
EDIT:
It seems anyway that using MY_Controller also forces CI to use the system Controller class, thus bypassing ME.
Thats an issue we should take up with Ellislab. :lol:
#459 / Jun 05, 2008 8:51am
Right now it would be good to notice it in the wiki.
#460 / Jun 05, 2008 10:03am
You’re welcome to add it to the wiki Sam. Thanks 😉
#461 / Jun 05, 2008 10:25am
Done. Don’t you mind I’ll add some HMVC info to wiki page also?
#462 / Jun 05, 2008 10:53am
Sure, it is a community project.
#463 / Jun 06, 2008 6:21am
wiredesignz
Have a question about where to keep my custom controller classes.
It seems that they need to be put into Controller.php and can’t be loaded via plugins/libraries since they are initializing after constructing controller. For now I’ve included custom_controllers.php just from the end of HMVC’s Controller.php but I think it’s a bad way…
#464 / Jun 06, 2008 9:59pm
I haven’t had the time to read through all 40-something pages of this topic, so maybe this question has already been answered:
Is there a way to know if a controller is called directly (through url) or called by another controller?
If there was a way to know this, you could create modules that have a layout when they are called directly, and don’t have a layout if they are called by another controller.
To clarify: sometimes you want the same module to be accessible directly through the url, and then you need the module to have a layout (theme or skin) and sometimes you want to call that same module as a small part of another controller/page. In that case, you don’t need the whole layout/theme to appear. That’s why it would be handy to know which way a module is called.
#465 / Jun 06, 2008 10:35pm
@gerben, I would check the uri->segments for the controller name.