ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Modular Separation - PHP5 (Modules)

July 02, 2009 12:38am

Subscribe [88]
  • #76 / Jan 13, 2010 11:00am

    Alface

    41 posts

    to use DMZ with HMVC I hacked datamapper libraries (system\application\libraries)
    I couldn’t extend without losing the functionality to make a custom datamapper’s extended class for each module
    actily, I think it is not even possible to extend autoload datamapper native class.

    static function autoload($class)
        {
            // Don't attempt to autoload CI_ or MY_ prefixed classes
            if (in_array(substr($class, 0, 3), array('CI_', 'MY_')))
            {
                return;
            }
    
            // Prepare class
            $class = strtolower($class);
    
            // Seach on application folder
            // Prepare path
            $path = APPPATH . 'models';
    
            // Prepare file
            $file = $path . '/' . $class . EXT;
            
            
            // Check if file exists, require_once if it does
            if (file_exists($file))
            {
                require_once($file);
            }
            else
            {
                // Do a recursive search of the path for the class
                DataMapper::recursive_require_once($class, $path);
            }
            
            
            
            // Seach on Modules folders
            
            // Prepare path
            $path = APPPATH . 'modules';
            
            if(is_dir($path) ){
                if ($handle = opendir($path)){
                    while (FALSE !== ($dir = readdir($handle))){
                        // If dir does not contain a dot
                        if (strpos($dir, '.') === FALSE){
                            $modules[] = $dir;
                        }
                    }
                }
            }
            
            foreach($modules as $module){
                // Prepare path
                $path = APPPATH . 'modules/'.$module.'/models';
                
                // Verify if there is a models folder on Module folder
                if(is_dir($path) ){
                    // Prepare file
                    $file = $path . '/' . $class . EXT;
        
                    // Check if file exists, require_once if it does
                    if (file_exists($file))
                    {
                        require_once($file);
                    }
                    else
                    {
                        // Do a recursive search of the path for the class
                        DataMapper::recursive_require_once($class, $path);
                    }
                }
            }
        }

    I needed to edit system\application\datamapper\htmlform.php too
    turn it

    // this is the default template (view) to use for the overall form 
        var $form_template = 'dmz_htmlform/form';
        // this is the default template (view) to use for the individual rows
        var $row_template = 'dmz_htmlform/row';
        // this is the default template (view) to use for the individual rows
        var $section_template = 'dmz_htmlform/section';

    intro this

    // this is the default template (view) to use for the overall form 
        var $form_template = '../dmz_htmlform/form';
        // this is the default template (view) to use for the individual rows
        var $row_template = '../dmz_htmlform/row';
        // this is the default template (view) to use for the individual rows
        var $section_template = '../dmz_htmlform/section';

    I think it will work with any Modular Extension (ME) like Matchbox.
    I didn’t find any post about it on the forum, if anyone know a better way to do it, let me know

  • #77 / Jan 14, 2010 1:19pm

    zorrito

    7 posts

    I have a class current_user.php in my modules/login/models directory, Current_user is a Singleton Pattern.

    in my controller (mymodules/login/controllers) i load my model.

    $this->load->model('login/current_user');
    <?php
    class Current_User { 
    private static $user;
    private function __construct() {}
    public static function user() {
    .......

    I can’t call private method.

    Fatal error: Call to private Current_User::__construct() from context ‘MY_Loader’ in C:\wamp\www\ci_doctrine\system\application\libraries\MY_Loader.php on line 147

    How do you solve this?

    After that i made a public constructor, and then i have this error.

    Fatal error: Call to undefined method Current_User::_assign_libraries() in C:\wamp\www\ci_doctrine\system\application\libraries\MY_Loader.php on line 192

    Any ideas?

    If i put current_user.php on normal models rep all is good (if i don’t load model in my controller (mymodules/login/controllers) )

    Cheers.

    P.S : sorry for my english

  • #78 / Jan 17, 2010 7:24pm

    hugle

    289 posts

    Hello wiredesignz!
    big thanks at first 😊

    Certainly I came across one problem,
    somehow, MY_Router.php tries to load lover-case library name.
    The file itself exists, but starts from upper case, it’s named Settings.php

    The error I get is:

    A PHP Error was encountered
    Severity: Warning
    Message: Modules::include_once(application/modules/core/settings/libraries/settings.php) [function.Modules-include-once]: failed to open stream: No such file or directory
    Filename: libraries/MY_Router.php
    Line Number: 158

    and if I add:

    $location = str_replace('settings.php', 'Settings.php', $location);

    before the:

    include_once $location; //line 158, MY_Router.php

    It starts working…

    I can’t reproduce it myself.. can you help me or someone else?
    Thank you for your time and thoughts!:)

  • #79 / Jan 17, 2010 11:31pm

    wiredesignz

    2882 posts

    @hugle, Thanks, there is a bug in Modules::find() that incorrectly returns the lowercase filename for module/libraries to the loader.

    Try altering the two lines in MY_Router.php after line 182

    // line 182
    $file = array_pop($segments);
    if ($base == 'libraries/') $file = ucfirst($file);
    $file_ext = strpos($file, '.') ? $file : $file.EXT;

    If that fixes the issue I will post a proper update.

  • #80 / Jan 18, 2010 2:15am

    hugle

    289 posts

    @hugle, Thanks, there is a bug in Modules::find() that incorrectly returns the lowercase filename for module/libraries to the loader.

    Try altering the two lines in MY_Router.php after line 182

    // line 182
    $file = array_pop($segments);
    if ($base == 'libraries/') $file = ucfirst($file);
    $file_ext = strpos($file, '.') ? $file : $file.EXT;

    If that fixes the issue I will post a proper update.

    Hello, you are fast 😊
    I confirm, replacing these lines:

    $file = array_pop($segments);
    $file_ext = strpos($file, '.') ? $file : $file.EXT;
    if ($base == 'libraries/') $file_ext = ucfirst($file_ext);

    With yours:

    $file = array_pop($segments);
    if ($base == 'libraries/') $file = ucfirst($file);
    $file_ext = strpos($file, '.') ? $file : $file.EXT;

    Works with no problem!:)
    Thank you very much, cause my solution was was pretty ugly:)))))))

  • #81 / Jan 18, 2010 5:40am

    wiredesignz

    2882 posts

    Modular Separation PHP5 version 1.10 is attached to this post.

    Fixed a file naming convention problem when loading module/libraries. Thanks hugle. 😉

    EDIT:
    Removed deprecated version 1.10.

  • #82 / Jan 21, 2010 12:10pm

    mreeves

    30 posts

    Seem to have a problem and i’m wondering whether modular separation is the where the answer lies. Basically I have a modular app and development has been going nicely. Today I started a business directory module. The name I gave to the module is “directory” and coded it. If I visit http://site/directory I just get a blank screen. After much investigation if I simply change the name of the module and the directory.php within it to something else it works. “directory” does not appear to be a reserved word in CodeIgniter so is it something to do with Modular Separation?

    If anyone can shed some light on this it would be much appreciated.

    best regards
    Martin

    P.S. I should add i’ve tried upgrading to the latest version.

  • #83 / Jan 21, 2010 2:15pm

    hugle

    289 posts

    Modular Separation PHP5 version 1.10 is attached to this post.

    Fixed a file naming convention problem when loading module/libraries. Thanks hugle. 😉

    hello:)
    no problem wiredesignz, I’m glad that we were able to fix something new 😊

  • #84 / Jan 21, 2010 3:13pm

    haydenp

    46 posts

    @mreeves

    I’m using the latest version of Modular Seperation and have a module named ‘directory’. All is working okay for me.

    Any routing possibly causing the problem?

  • #85 / Jan 21, 2010 4:01pm

    mreeves

    30 posts

    @mreeves

    I’m using the latest version of Modular Seperation and have a module named ‘directory’. All is working okay for me.

    Any routing possibly causing the problem?

    Many thanks for checking Hayden. I’m at a complete loss as to how to solve this. There are no routes defined that could be conflicting as far as I can see and simply changing the name of the module and controller to something else gets it working. Bizarre and frustrating.

  • #86 / Jan 21, 2010 4:36pm

    haydenp

    46 posts

    Martin

    2 things ...

    1. You say you are getting a blank screen. I would have thought you would see an error message of sorts? Are you set up to see all errors? May shed some ligt.

    2. As far as I’m aware, MS will always search in application/controllers first to see if there is a controller there with the specified name ie. application/controllers/directory.php If none is found then only does it look for a module with the specified name ie. application/modules/directory/...

    Check if you dont have a controller lurking about with a matching name.

    Hayden

  • #87 / Jan 21, 2010 4:45pm

    mreeves

    30 posts

    Found the problem - it appears Directory is a reserved word in PHP

  • #88 / Jan 24, 2010 3:51am

    shinokada

    144 posts

    A quick question.
    Can anyone tell me where I can download this?
    When I click Wiredesignz’s signature Modular separation, it comes back to this forum.

    Thanks in advance.

  • #89 / Jan 24, 2010 12:53pm

    hugle

    289 posts

    A quick question.
    Can anyone tell me where I can download this?
    When I click Wiredesignz’s signature Modular separation, it comes back to this forum.

    Thanks in advance.

    Hello

    here you go,
    it is the most up to date version 😊

    http://codeigniter.com/?ACT=51&fid=58&aid=9479_3X78KndCZsFZBkD14oyx&board_id=2

  • #90 / Jan 25, 2010 3:32am

    shinokada

    144 posts

    Thanks hugle.
    Is there any manual about how to use?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases