Welcome Guest, Not a member yet? Register   Sign In
Modular Extensions - HMVC version 5.3

[eluser]wilso417[/eluser]
Hey guys,

Adding a config/routes.php inside a module folder does not work as expected. I assumed adding specific routes inside a module would behave exactly like if I was tacking those on at the end of app/config/routes.php. However, this does not work as expected... it seems like config/routes.php is then used just to send to the module and will not follow the whole routing is matched. Instead it behaves like config/routes.php just gets the module, then the module specific routes does the rest. Is this correct?

[eluser]wilso417[/eluser]
For instance:

app/config/routes.php:

$route['admin/([a-zA-Z_-]+)/(:any)'] = "$1/admin/$2";

modules/news/config/routes.php:

$route['news/:any'] = "news/views/$1";

any url like: admin/news/function will reroute to news/views/function instead of news/admin/function. Now if I put the module specific routes inside the app routes, it will reroute as expected.

[eluser]wiredesignz[/eluser]
The module name is not needed in the route value. It is assumed.

Code:
$route['news(.*)'] = 'views$1';

//or

$route['news'] = 'views';
$route['news/(.*)'] = 'views/$1';

This segments will be a controller/method or sub-directory/controller/method etc

[eluser]iloveci[/eluser]
I've just recently downloaded this and started playing around with it after seeing it put to good use in pyrocms. I just wanted to thank you for sharing it wiredesignz.

[eluser]wiredesignz[/eluser]
@iloveci, You're welcome, thanks.

[eluser]loosetops[/eluser]
Hi Wired

modules::run is not working. No error given, just returns nothing.

I this kind of set up

Code:
class MY_Controller extends MX_Controller
class Member_Controller extends MY_Controller

class Home extends Member_Controller //<-- modules/thesaurus/controllers/home
class Home extends Member_Controller //<-- modules/content_creator/controllers/home

In the content_creator module I try to run a method in the thesaurus controller
Code:
$this->data['thesaurus_widget'] = modules::run('thesaurus/widget');
//OR
$this->data['thesaurus_widget'] = $this->load->view('thesaurus/widget_view',TRUE);

Now thesaurus/widget routes to thesaurus/home/widget and
there is modules/thesaurus/view/widget_view.php

I can access the widget fine from the url, but both cross loading techniques return nothing. No error. In fact modules::run doesn't even call the controller method(I put an exit; in there to test).

load->view complains if I give it a non-existent view file but modules::run does not.

All this is on localhost

Thanks

[eluser]wiredesignz[/eluser]
Is there a reason that you need to use modules::run via the routing instead of directly?

Code:
modules::run('thesaurus/home/widget');


You may not see anything from modules::run while testing because output is buffered.

[eluser]loosetops[/eluser]
[quote author="wiredesignz" date="1288972377"]Is there a reason that you need to use modules::run via the routing instead of directly?

Code:
modules::run('thesaurus/home/widget');


You may not see anything from modules::run while testing because output is buffered.[/quote]

I have tried both to same effect.

Is there a way to tell if the output is buffered? I kinda doubt that is happening as I have tried echoing whatever is returned. And an exit; in the controller function being called by run() doesn't event halt the program.

Edit:
I might have found a bug. I realized my error logging wasn't on turning it on shows the errors
Code:
modules::run('thesaurus/home/widget');
ERROR - 2010-11-05 09:52:53 --&gt; Module controller failed to run: thesaurus/home/home/widget

//AND
modules::run('thesaurus/widget');
ERROR - 2010-11-05 09:53:49 --&gt; Module controller failed to run: thesaurus/widget

For some reason the run method adds a 2nd controller class. Given module/controller/method it tries to run module/controller/controller/method

I have no clue why it is doing that.

[eluser]loosetops[/eluser]
third_party / MX / Modules.php is faulty

Code:
52    public static function run($module) {
53        
54        $method = 'index';
55        
56        if(($pos = strrpos($module, '/')) != FALSE) {
57            $method = substr($module, $pos + 1);        
58            $module = substr($module, 0, $pos);
59        }
60    
61        $controller = end(explode('/', $module));
62        if ($controller != $module) $controller = $module.'/'.$controller;
63        
64        if($class = self::load($controller)) {
65            
66            if (method_exists($class, $method))    {
67                ob_start();
68                $args = func_get_args();
69                $output = call_user_func_array(array($class, $method), array_slice($args, 1));
70                $buffer = ob_get_clean();
71                return ($output) ? $output : $buffer;
72            }
73        }
74        
75        log_message('error', "Module controller failed to run: {$controller}/{$method}");
76    }

Given
Code:
modules::run('module/controller/method');

An echo at line 63
Code:
echo $module,'<br />',$controller,'<br />',$method,'<br />';

//yields
module
module/controller/controller
method

As a result the ifs at lines 64 or 66 fail.

The self::load at 64 may be loading the wrong controller leading to a fail at 66.

[eluser]wilso417[/eluser]
[quote author="wiredesignz" date="1288837291"]The module name is not needed in the route value. It is assumed.

Code:
$route['news(.*)'] = 'views$1';

//or

$route['news'] = 'views';
$route['news/(.*)'] = 'views/$1';

This segments will be a controller/method or sub-directory/controller/method etc[/quote]

I tried that with this:

app/config/routes.php:

$route[‘admin/([a-zA-Z_-]+)/(:any)’] = “$1/admin/$2”;

modules/news/config/routes.php:

$route[‘news/:any’] = “views/$1”;

still does not work with a url of admin/news/function. It redirects to news module only, and then modules/news/config/routes.php tries to redirect and goes to 404. If I do:

app/config/routes.php:

$route['admin/([a-zA-Z_-]+)/(:any)'] = "$1/admin/$2";
$route['news/(:any)'] = "news/view/$1";

That will work. That is how i'd expect putting routes in my module folder, that it'd be a lower precedence but that is not the case. What is the point of putting routes inside a module then?




Theme © iAndrew 2016 - Forum software by © MyBB