Welcome Guest, Not a member yet? Register   Sign In
HMVC Current module name
#1

[eluser]emateu[/eluser]
Hi, I'm working with hmvc. I need to get the current module name...

For example, if I'm in: http://localhost/index.php/mymodulename/controller/method. I would like to get mymodulename string from any class, controller, library or whatever.

Doing:
Code:
$RTR =& load_class('Router', 'core');
echo $RTR->fetch_module();
Is not working with the same logic as
Code:
$RTR->fetch_class();
or
Code:
$RTR->fetch_method();


Regards!
#2

[eluser]PhilTem[/eluser]
Why do you load the router class? You can get the module's name easily via

Code:
$this->_module = $this->router->fetch_module();
// or
global $RTR;
$this->_module = $RTR->fetch_module();

though I haven't tried the second one Wink
#3

[eluser]emateu[/eluser]
This don't work:
Code:
$this->router->fetch_module();

It give me the name of the module where I execute the line. I want to get the module of the query string!

Thanks
#4

[eluser]PhilTem[/eluser]
Well.... That should actually be the same (if you're calling the all properly). Either I didn't get what you were wanting go get or you don't know what you want to get or explained what you want to get properly.
#5

[eluser]emateu[/eluser]
Okay, here I go:

Two files:
A) application/modules/emateu/controllers/emateu.php
Code:
class Emateu extends MX_Controller {
    
    public function get_module_name () {
        return  $this->router->fetch_module();
    }
    
    public function get_class_method () {
        return $this->router->fetch_class().' - '.$this->router->fetch_method();
    }
}


B) application/modules/helloworld/controllers/helloworld.php
Code:
class Helloworld extends MX_Controller {

    public function index () {
        $this->load->module('emateu');
        
        die( $this->emateu->get_module_name() );
    }
    
    public function test () {
        $this->load->module('emateu');
        
        die( $this->emateu->get_class_method() );
    }
}

So, when I request: http://localhost/index.php/helloworld/helloworld/index , I'm getting "emateu" as result and I expect to get "helloworld" because I'm on: http://localhost/index.php/helloworld/helloworld/index.
I said that is not working like fetch_class() or fetch_method() because when request: http://localhost/index.php/helloworld/helloworld/test I'm getting "helloworld - test" instead of "emateu - get_class_method" and thats okay, but fetch_module() is not working like that and I would like to have a similar criteria if its possible.

I hope I have explained. Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB