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

[eluser]a&w[/eluser]
[quote author="wiredesignz" date="1216370705"]Check the user_guide regarding routes or study up on regex.[/quote]...or leave it alone and come back fresh. :red:

The last line of my prior post had that option as well. Can't figure it, something must have been caching somewhere or something. Went to bed with it not working and tried again this morning and it's working.
#82

[eluser]wiredesignz[/eluser]
Sleeping is very good for the debug gremlins.
#83

[eluser]a&w[/eluser]
[quote author="mark17" date="1216301321"]Thanks for your reply.

I guess we cannot use the MY_Model library class either?
I will perform some tests and see if we can use it.[/quote]

mark17: in case you find it useful I'll elaborate on what wiredesignz said.

ME_5 uses these files:
1. application/libraries/Controller.php - replaces CodeIgniter's base application controller.
2. application/libraries/MY_Router.php - supplements CodeIgniter's router class.
3. application/libraries/Modules.php

That's it, no model class.

The front index.php loads the front controller for the system.... CodeIgniter.php.

CodeIgniter.php loads all of the base classes and then the local controller and method called by the url.

CodeIgniter.php uses the following method to load the base classes:

Code:
//from system/codeigniter/common.php
function &load;_class($class, $instantiate = TRUE)
{
    static $objects = array();

    // Does the class exist?  If so, we're done...
    if (isset($objects[$class]))
    {
        return $objects[$class];
    }

    // If the requested class does not exist in the application/libraries
    // folder we'll load the native class from the system/libraries folder.    
    if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT))
    {
        require(BASEPATH.'libraries/'.$class.EXT);    
        require(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT);
        $is_subclass = TRUE;    
    }
    else
    {
        if (file_exists(APPPATH.'libraries/'.$class.EXT))
        {
            require(APPPATH.'libraries/'.$class.EXT);    
            $is_subclass = FALSE;    
        }
        else
        {
            require(BASEPATH.'libraries/'.$class.EXT);
            $is_subclass = FALSE;
        }
    }
So this means:
1. if there is a MY_whateverClass (MY_Controller in this case) in your application/libraries directory it will load that in addition to the CI version of that class. It will then not load the Controller.php file that is part of ME_5 as a result.
2. if there is no MY_whatever class THEN it checks if there is an override in the application directory, otherwise just loads the original CI version of that class.

I didn't understand the 'why' of what was going on before and now understand it better (I think?) so thought I'd share that in case it also helped you or someone else.

I'm still looking into how to get by without MY_Controller, or what changes are required to automatically load a version of it. I think there's a way to autoload it?
#84

[eluser]Sam Dark[/eluser]
a&w;, you can just include you base_controllers.php with some base controllers form the end of Controller.php.
#85

[eluser]a&w[/eluser]
[quote author="Sam Dark" date="1216696482"]a&w;, you can just include you base_controllers.php with some base controllers form the end of Controller.php.[/quote]
Ok, I'll have a look. I was wondering if something like this might be put into ME's Controller.php file:

Code:
// Put MY_Controller in the application/controllers directory instead of
// application/libraries directory if want to use it.
    if (file_exists(APPPATH.'controllers/'.config_item('subclass_prefix').'Controller'.EXT))
    {
        require(APPPATH.'controllers/'.config_item('subclass_prefix').'Controller'.EXT);

        //$is_subclass = TRUE;    

        //not sure about this part
        $name = config_item('subclass_prefix').'Controller';
        $objects[$class] =& new $name();
        return $objects[$class];
    }
So basically, if someone HAD a MY_Controller file, all they would have to do is move it from application/libraries (where it would circumvent ME5 controller from loading) to application/controllers and it would just 'work' without hacking Controller.php.

I don't quite get how the class is being registered though, as I commented in the code above, seems like the original code from Common.php would replace the reference to Controller.php with a reference to MY_Controller.php.

Edit: Ok, maybe I understand it now, the reference in the objects array is changed to point to the subclass (MY_Controller.php), which extends the base class (Controller.php). So I see how that would work. So in that case I guess this would be the resulting code:
Code:
// Put MY_Controller in the application/controllers directory instead of
// application/libraries directory if want to use it.
    if (file_exists(APPPATH.'controllers/'.config_item('subclass_prefix').'Controller'.EXT))
    {
        $name = config_item('subclass_prefix').'Controller';
        require(APPPATH.'controllers/'.$name.EXT);
        $objects['Controller'] =& new $name();
        return $objects['Controller'];
    }
#86

[eluser]a&w[/eluser]
If you want to use MY_Controller with ME 5, this small bit of code seems to work.

Just put MY_Controller.php in application/controllers instead of application/libraries and add this snippet of code to application/libraries/Controller.php:
Code:
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');

/* load the modules library */
require_once 'Modules.php';

// Put MY_Controller in the application/controllers directory instead of
// application/libraries directory if you want to use it.
$name = config_item('subclass_prefix').'Controller';
if (file_exists(APPPATH.'controllers/'.$name.EXT))
{
//    $name = config_item('subclass_prefix').'Controller';
    require(APPPATH.'controllers/'.$name.EXT);
}

/**
* Modular Extensions - PHP5
*
* Adapted from the CodeIgniter Core Classes
* @copyright    Copyright (c) 2006, EllisLab, Inc.
* @license        http://ellislab.com/codeigniter/user-guide/license.html
*
* Description:
* This library is used by CodeIgniter to instantiate controllers
* and module controllers.
*
* Install this file as application/libraries/Controller.php
*
* @version: 5.0.27 (c) Wiredesignz 2008-07-09
**/
class Controller extends CI_Base
#87

[eluser]a&w[/eluser]
[quote author="wiredesignz" date="1215845076"]A module should be considered as a mini application, self contained and controllers are the entry point.

An auth module, for instance, would contain controllers, libraries, helpers and views related to auth, the auth controller(s) would be called to get user status, display login form, check privileges, and anything else related to auth you might like to add.[/quote]
I'd like to confirm I'm going about this the right way if I may.

If I have:

Code:
L modules
   L module1
      L controllers
         module1.php
      L libraries
         module1_lib.php
   L module2
      L controllers
         module2.php
      L libraries
         module2_lib.php
What I've been doing to call Module2 resources from Module1 is to set up accessors like so:

Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Module2 Module Controller
*
**/
class Module2 extends Controller {

    function __constructor()
    {
    parent::Controller();
    }

    function getModel($model, $name = '', $db_conn = false)
    {
        $this->load->model($model, $name, $db_conn);
        log_message('debug', get_class($this)." Model Initialized");
    }

    function getLibrary()
    {
        $this->load->library('module2_lib');
        log_message('debug', get_class($this)." Library Initialized");
    }
    
    function index()
    {        

    }

}
Is that better? Or am I still off track?

Also, for some of the libraries I am using they would sometimes get a reference to the CI object and load resources from within that library. Would it be better HMVC form to move those responsibilities from the module's library to the module's controller? Using the above code as an example something like:

Code:
function getLibrary()
    {
        $this->load->library('module2_lib');

        //load any resources needed by this library
        $this->module('module3')->getLibrary();

        log_message('debug', get_class($this)." Library Initialized");
    }

I think I'm a little hung up on the CI way of loading or even how Matchbox does it where you can load a resource (eg. library) from another module straight away using something like
Code:
$this->CI->load->module_library('moduleName','libraryName');
...just trying to get my head wrapped around this. Smile
#88

[eluser]wiredesignz[/eluser]
@a&w,
If a library is required by more than one module I would consider it a SHARED resource and locate it in application/libraries and load it as needed from each module.
#89

[eluser]Sam Dark[/eluser]
a&w;, MY_Controller solution seems to be useful… wiredesignz, what do you think?
#90

[eluser]wiredesignz[/eluser]
Yeah it's ok if you need this functionality. I'm not too happy with the idea of base controllers being accesible from the URL... However I will add the following code to Controller.php in the next release for you.

Code:
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');

/* load the modules library */
require_once 'Modules.php';

/* PHP5 autoload helper */
function __autoload($class)
{
    if (is_file($filename = APPPATH.'libraries/'.$class.EXT))
        
        include_once $filename;
}

/*
* Modular Extensions - PHP5
*/
This will allow you to use any application/libraries/Base_Controller.php class name

Any comments would be appreciated before I commit this.




Theme © iAndrew 2016 - Forum software by © MyBB