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]
  • #106 / Feb 28, 2010 10:51pm

    theprodigy

    653 posts

    I just thought about it. Maybe it’s the way I’m loading my models. I have the constructor of my MY_Controller loading the models. Is it possible that MY_Model just isn’t loaded yet?

    My MY_Controller constructor looks like this:

    public function __construct()
    {
        parent::__construct();
            
        foreach( $this->models as $model )
        {
            $this->load->model( $model . '_model', $model );
        }
    }

    Could this be the problem? If so, why would MX_Model be loaded but not MY_Model?

  • #107 / Mar 01, 2010 4:34am

    Phil Sturgeon

    2889 posts

    Modular Separation PHP5 has been updated and version 1.11 is now attached to the first post of this thread.

    Any change you could maintain a changelog? I’m glad this is actively developed but I dont like updating just for the sake of it. 😊

  • #108 / Mar 01, 2010 6:05am

    wiredesignz

    2882 posts

    Only one change to load->database() to match the HMVC update.
    You know how to run a diff Phil. 😉

  • #109 / Mar 01, 2010 6:12am

    Phil Sturgeon

    2889 posts

    HA cheeky bastard. Of course I ran a diff before committing the change, would be nice for at least a sentence saying “fixed bug a but doing thing b” when you announce a new version.  😛

  • #110 / Mar 04, 2010 12:21am

    theprodigy

    653 posts

    ok, I stopped loading the models in the MY_Controller constructor and I am still getting “Fatal error: Class ‘MY_Model’ not found in path/to/my/model.php on line 8”. Please enlighten me on how to get this to work.
    Thanks

  • #111 / Mar 04, 2010 12:27am

    wiredesignz

    2882 posts

    There is no secret to using MY_ class extensions. Just make sure you follow the CodeIgniter conventions properly.

    File naming and class naming rules are especially important.

  • #112 / Mar 04, 2010 12:29am

    theprodigy

    653 posts

    I understand that. I’ve used them quite a few times. But for some reason, it’s not working for me with your Modular Extensions. I would love to continue using it, so I am trying to find out why CI won’t load the MY_Model class. MY_Controller works just fine, but the MY_Model won’t. It’s very strange.

  • #113 / Mar 04, 2010 12:46am

    theprodigy

    653 posts

    Even when trying to use the model when not in a module, it won’t load properly.

    Maybe it is my setup. I’m not sure. Here is what I have:
    MY_Model (located in application/libraries/) :

    <?php
    class MY_Model extends Model
    {
        #    class variables
        protected $table;
        
        #    Constructor
        public function __construct()
        {
            parent::__construct();
        }
    // ...[more code]... //
    }

    And here is my model inside of my blog module

    <?php
    class blog_model extends MY_Model
    {
        public function __construct ()
        {
            # code…
            parent::__construct();
            $this->table = 'blog';
        }
        // ...[more code]... //
        
    }

    and since my MY_Controller works, here it is for comparison.
    MY_Controller (located in application/libraries/) :

    <?php
    class MY_Controller extends Controller
    {
        protected $module;
        protected $controller;
        protected $method;
        protected $inner_view = '';
        protected $template = 'template';
        protected $data = array();
        
        public function __construct()
        {
            parent::__construct();
            
            $this->module = $this->router->fetch_module();
            $this->controller = $this->router->class;
            $this->method = $this->router->method;
            $this->inner_view = $this->module . DIRECTORY_SEPARATOR
                    . $this->controller . DIRECTORY_SEPARATOR
                    . $this->method;
        }
    // ...[more code]... //
    }
  • #114 / Mar 04, 2010 2:37am

    wiredesignz

    2882 posts

    Well I can assure that using MY_Model works fine with Modular Separation so the problem lies in your code or your installation.

    Blog_model class name is important but probably not the issue here.

    And the file name should be blog_model.php

    MY_Model.php file name is important too.

    Call parent::__construct() before other code in the Blog_model class constructor.

  • #115 / Mar 04, 2010 3:02am

    theprodigy

    653 posts

    I found it.
                                       
    I copied this app from what I thought was a blank version, and I ended up having some left over code in the autoload.php config file.
                                         
    I removed the autoload, and everything is working as expected. Sorry for the thread spam.

  • #116 / Mar 05, 2010 9:21am

    CI flea

    8 posts

    I have quite a big application which at present uses Matchbox 0.9.3. I’ve had problems trying to update it to the last version of Matchbox, so decide to try Modular Separation. I was surprised by just removing Matchbox and dropping Modular Separation into my library folder that everything worked, except for one problem I found.

    I have separated my views into subfolder for organisational reasons, and everything worked fine. However with Modular Separation I find that if I have a view subfolder with the same name as the Module, it is not able to load these files. A quick change of name for the view subfolder and everything works, however I have hundreds of these across my whole application.

    eg.

    I have a module called Documents, then in my Views folder I have a subfolder called documents. Modular Separation is not able (and throws no errors) to load files from this subfolder. If I rename my subfolder as document (no s), everything works fine.

    I running CI 1.7.2 and php 5.3, with MS 1.11.

    I would also like to know if it’s possible to move the modules folder from the Application folder to my application root folder.

    thanks

  • #117 / Mar 05, 2010 5:09pm

    wiredesignz

    2882 posts

    ... if it’s possible to move the modules folder from the Application folder to my application root folder.

    Use the Modules::$locations array setting. See MY_Router.php

  • #118 / Mar 10, 2010 7:52am

    CI flea

    8 posts

    Thanks,

    I’ve tried to set Modules::$locations but not not had any success yet;

    I would like to put the modules folder in the web rot. This is what I’ve tried so far,

    Modules::$locations = array(
        'path/to/web/' => '../modules/',
    );

    also tried various combinations of ‘../modules/’, ‘.modules/’, etc.

    Thanks

  • #119 / Mar 10, 2010 9:01am

    Sean Downey

    34 posts

    Hi

    Thanks for the library it looks great.
    In early testing at the moment and came across an issue which I haven’t see in the forum thread.

    MY_Controller calls

    $this->load->library('member/memberlib');

    all good
    but in the memberlib.php constructor I call

    $this->CI = &get;_instance();
    $this->CI->load->config('memberlib');

    I get

    The configuration file userlib.php does not exist.

    It works if I use

    $this->CI->load->config('member/memberlib');

    but should it work without specifying the module?

    Thank you

  • #120 / Mar 10, 2010 1:22pm

    darkhouse

    323 posts

    I love this system.  It’s made my app quite powerful and flexible. I’ve integrated the modules into a new CMS we’re developing.  Thank you for providing it.

    However, I had a problem where I had a uri ‘/students/gallery’ that was trying to load the gallery module I have (modules/gallery/controllers/gallery) instead of loading the page that the gallery module is used on.  The reason is because there is no physical students/gallery page, instead these are slugs in a database, so the router didn’t find the page, but did find the module and broke my page.

    I solved this by removing the first line in the _validate_request function in the extended router class:

    public function _validate_request($segments) {        
            
        /* locate module controller */
        //if ($located = $this->locate($segments)) return $located; <-- this line
    
        /* use a default 404 controller */
        if (isset($this->routes['404']) AND $segments = explode('/', $this->routes['404'])) {
            if ($located = $this->locate($segments)) return $located;
        }
        
        /* no controller found */
        //my custom code to load the cms system goes here, instead of showing a 404 error
    }

    Now everything is working as it should.  I just want to confirm that this line is only there so that under normal circumstances, if a physical controller is not found, it will look for a module using that uri, and that by removing it, all I’m losing is the ability to use the uri to load a module.  Is that correct?

    Thanks!

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

ExpressionEngine News!

#eecms, #events, #releases