Welcome Guest, Not a member yet? Register   Sign In
Modular Extensions - Version 4.3

[eluser]dfau[/eluser]
Hi wiredesignz,

Thanks for the new version - I've dropped .18 into my testing app and I get:
Code:
Unable to locate the requested file: ../application/views/foobar/one.php

My master controller (application/controllers/welcome.php):
Code:
class Welcome extends Controller {
    function Welcome() {
        parent::Controller();
    }
    function index() {
        $data['content'] = modules::run('foobar', NULL, 'one', TRUE);
        $this->load->view('welcome_message', $data);
    }
}

My module (application/modules/foobar/controllers/foobar.php):
Code:
class Foobar extends Controller {
    function
    Foobar() {
        parent::Controller();
    }
    function
    one() {
        return $this->load->view('one', NULL, TRUE);
    }
}

My module's view for function "one" (application/modules/foobar/views/one.php):
Code:
<p>This is: /modules/foobar/views/one.php</p>

It looks like the search paths have gone funny - here is the debug that I put into modules_helper.php:
Code:
diff --git a/application/helpers/modules_helper.php b/application/helpers/modules_helper.php
index 756043f..3bd16de 100644
--- a/application/helpers/modules_helper.php
+++ b/application/helpers/modules_helper.php
@@ -147,6 +140,7 @@
        **/
        function modules_find($file, $path = '', $base = 'controllers/', $subpath = '')
        {
+echo "looking for {$file} path={$path} base={$base} subpath={$subpath}\n";
                if (($pos = strrpos($file, '/')) !== FALSE)
            {
                        $path = substr($file, 0, $pos);
@@ -180,6 +174,8 @@

                $file_ext = strpos($file, '.') ? $file : $file.EXT;

+echo "paths2scan: ";
+print_r($paths2scan);
                foreach ($paths2scan as $path2)
                {
                        //echo '<p>',$path2,$file_ext,'</p>';
@@ -188,7 +184,10 @@
                        {
                                if (is_file($path2.$name))
                                {
+                                       $home = explode('/', $path2);
+echo "found: ";
+echo print_r(array($path2, $file, $home[2]), TRUE), "\n";
+                                       return array($path2, $file, $home[2]);
                                }
                        }
                }
and here are the results from loading the base url:
Code:
looking for autoload path=welcome base=config/ subpath=welcome
paths2scan: Array
(
    [0] => ../application/modules/welcome/config/
    [1] => ../application/config/
    [2] => ../application/config/welcome/
)
found: Array
(
    [0] => ../application/config/
    [1] => autoload
    [2] => config
)

looking for foobar path=foobar base=controllers/ subpath=welcome
paths2scan: Array
(
    [0] => ../application/modules/foobar/controllers/
    [1] => ../application/controllers/
    [2] => ../application/controllers/foobar/
    [3] => ../application/modules/foobar/controllers/welcome/
    [4] => ../application/controllers/welcome/
)
found: Array
(
    [0] => ../application/modules/foobar/controllers/
    [1] => foobar
    [2] => modules
)

looking for autoload path=modules base=config/ subpath=foobar
paths2scan: Array
(
    [0] => ../application/modules/modules/config/
    [1] => ../application/config/
    [2] => ../application/config/modules/
)
found: Array
(
    [0] => ../application/config/
    [1] => autoload
    [2] => config
)

looking for one path=modules base=views/ subpath=foobar
paths2scan: Array
(
    [0] => ../application/modules/modules/views/
    [1] => ../application/views/
    [2] => ../application/views/modules/
    [3] => ../application/modules/modules/views/foobar/
    [4] => ../application/views/foobar/
)

The last two searches include paths "../application/modules/modules/config", "../application/modules/modules/views" and "../application/modules/modules/views/foobar" which don't look right, and there is no "../application/modules/foobar/views" which is where the view lives.

If you could have a look at this that would be grouse.

Thanks,
df

[eluser]wiredesignz[/eluser]
Yes thanks again dfau Wink

Version 4.1.19 is on the wiki now.

Bugfix for path searches.

[eluser]dfau[/eluser]
Hi wiredesignz,

Thanks for the quick fix. If you're interested:
Quote:Test app: master controller, one module, one call from master to module, autoload database library, file and url helpers
4.1.18: memory usage 1,476,680 bytes
4.1.19: memory usage 1,470,820 bytes
5k saving, fantastic stuff. Thanks again,
df

[eluser]wiredesignz[/eluser]
Version 4.1.20 is available on the wiki now.

Refactoring code to improve speed and reduce memory usage.

Note* $this->load->contoller(); is now replaced with $this->load->module();

[eluser]sophistry[/eluser]
just poking deeper into the code today...

the MY_Router.php file has some unfamiliar code style. could you explain a few lines:
Code:
function _validate_request($segments)
    {
        ( ! isset($segments[1])) AND $segments[1] = 'index';

        /* locate the module controller */
        list($path, $file, $home) = $this->find($segments[1], $segments[0]);

        if ($path === FALSE)

            list($path, $file) = $this->find($segments[0], $segments[0]);

        /* no controllers were found */
        if ($path === FALSE)

            show_404($file);

        // set the directory path
        $this->set_directory(str_replace(APPPATH, '', $path));

        /* remove the directory segment */
        ($segments[1] == $file) AND $segments = array_slice($segments, 1);

        /* set the module home */
        ($home) AND my_router::path($home) OR my_router::path($file);

        return $segments;
    }

two lines i am curious about, the first line, what does this construction do? is it some kind of shortcut that works like an if statement because of the order of execution of the boolean?
Code:
( ! isset($segments[1])) AND $segments[1] = 'index';

also is this the same technique (boolean evaluation order)? what is ($home) doing there?
Code:
/* set the module home */
($home) AND my_router::path($home) OR my_router::path($file);
finally, in the same line shouldn't my_router::path() class function utilize the CI config setting in config.php:
Code:
$config['subclass_prefix'] = 'MY_';

thanks wired.

[eluser]Alex.[/eluser]
[quote author="sophistry" date="1212612526"]
two lines i am curious about, the first line, what does this construction do? is it some kind of shortcut that works like an if statement because of the order of execution of the boolean?
Code:
( ! isset($segments[1])) AND $segments[1] = 'index';
[/quote]
Yes, pretty much. It's almost exactly the same as:
Code:
if(!isset($segments[1])){
$segments[1] = 'index';
}

Quote:also is this the same technique (boolean evaluation order)? what is ($home) doing there?
Code:
/* set the module home */
($home) AND my_router::path($home) OR my_router::path($file);
If the variable $home evaluates to true, then the function path() stores the value of $home as the path. Else, it stores the value of $file as the path.
You could say it is the same as :
Code:
if($home){
my_router::path($home);
} else {
my_router::path($file);
}
Quote:finally, in the same line shouldn't my_router::path() class function utilize the CI config setting in config.php:
Code:
$config['subclass_prefix'] = 'MY_';
I'm confused - are saying that the name of the class should be dependent on the subclass prefix in the config file?
If you change the value of $config['subclass_prefix'], then you will have to change all references to the my_ extension manually.

[eluser]wiredesignz[/eluser]
Thanks Alex, nice explanation Wink

Yes, using my_router calls is an oversight, it will conflict with changes to subclass_prefix and should be noted in the docs.

[eluser]Sam Dark[/eluser]
I'm back into HMVC again. Good to see initial idea grew into the powerful lib.

Now about a bad thing…

I have a problem loading views in v. 4120. Got this error:

Code:
Unable to load the requested file: list.php

my app structure:

Code:
app/modules/files/
  controllers/files.php
  views/list.php

controllers/files.php
Code:
class Files extends Controller {
   function index($path = ''){        
       $this->load->view('list');
    }
}

Tried to put list.php into app/views/ and it works Sad

[eluser]wiredesignz[/eluser]
Works for me Sam. Wink

Try using the constructor parent::Controller(); so the module can find out where it lives.

[eluser]Sam Dark[/eluser]
Tried parent::__construct() but it doesn't helped.
btw, I'm trying to launch module directly with http://localhost/files/.




Theme © iAndrew 2016 - Forum software by © MyBB