Welcome Guest, Not a member yet? Register   Sign In
HMVC: Base.php vs. Ci.php
#11

[eluser]wiredesignz[/eluser]
Nothing is disabled. Things will function differently if you extend MX_Controller. HMVC is merely a design pattern you use in development, it's not a rule. There is nothing to stop you using modules::run (HMVC) without extending the MX_Controller class.
#12

[eluser]Maarten Troonbeeckx[/eluser]
@wiredesignz

How exactly do both approaches function differently then?
If extending CI_Controller and MX_Controller gIves me module separation and the ability to run multiple controllers, why have these two options in the first place?

Grtz, M.
#13

[eluser]wiredesignz[/eluser]
There are two options because they each have different requirements. There is no point loading and extending MX_Controller if you do not need to use HMVC. All you are doing is slowing down the application execution unnecessarily.
#14

[eluser]Maarten Troonbeeckx[/eluser]
@wiredesignz

So extending from MX_Controller is more performant than extending from CI_Controller when working with multiple controllers?
That's the difference?
#15

[eluser]wiredesignz[/eluser]
@Maarten Troonbeeckx, No, But wouldn't it be totally retarded to load a file that is not needed?
#16

[eluser]Maarten Troonbeeckx[/eluser]
Damn, this is frustrating :/
I'll try to explain myself again, hopefully better this time.
If I fail, you can call me a retard officially, instead of insinuating it Wink

I have the MX folder in the /third_party folder, both MY_Loader and MY_Router are in my application/core directory.

My understanding about what HMVC is:
- Modular separation (structure models/views/controllers in separate module folders)
- Ability to run multiple controllers in your application code (Modules::run())

If I extend MX_Controller a CI class (Base.php) is instantiated and used in MX_Controller's __get() to access loaded models/libraries, ...
If I extend CI_Controller a CI class (Ci.php) is instantiated which "decorates" the original CI_Controller with a static $APP variable, MX_Loader, ...

Btw, with CI_Controller I don't mean the standard CI_Controller, but the one that gets modified by Ci.php in the HMVC package!

[quote author="wiredesignz" date="1308964018"]In Base.php the CI class extends the CI_Controller class which holds the application object (CI::$APP) used to contain all of the CodeIgniter core classes. This allows you to use multiple controllers (HMVC) in your application. Your controllers must extend the MX_Controller class.

In Ci.php the CI class does not extend the CI_Controller, but still allows the use of the same code base to access the application object and the core classes. This only provides your application with modular separation, not HMVC. Your controller must extend the CI_Controller class.[/quote]

Your reply suggested to me that extending MX_Controller allows me to use multiple controllers and extending CI_Controller only provides my application with modular separation. This made me think that using multiple controllers was disabled in the second case and made sense to me...

[quote author="wiredesignz" date="1309055668"]Nothing is disabled. Things will function differently if you extend MX_Controller. HMVC is merely a design pattern you use in development, it's not a rule. There is nothing to stop you using modules::run (HMVC) without extending the MX_Controller class.[/quote]

Turned out I was wrong.

[quote author="wiredesignz" date="1309109413"]There are two options because they each have different requirements. There is no point loading and extending MX_Controller if you do not need to use HMVC. All you are doing is slowing down the application execution unnecessarily.[/quote]

But I do want to use HMVC, especially the modular separation part Wink
And everything seems to work the same way, whether I extend CI_Controller or MX_Controller.

So again, my question remains:
What's the difference between extending CI_Controller (not the regular one!) and MX_Controller, since in both cases you end up with an app allowing modular separation and the ability to use multiple controllers?

Hope I'm making more sense this time.

Grtz, M.
#17

[eluser]wiredesignz[/eluser]
[quote author="Maarten Troonbeeckx" date="1309183428"]...
What's the difference between extending CI_Controller (not the regular one!) and MX_Controller, since in both cases you end up with an app allowing modular separation and the ability to use multiple controllers?[/quote]

CI_Controller is the regular one. I have not modified the core controller class. MX_Controller stands alone from the CI_Controller core when we use it in HMVC context.
#18

[eluser]Maarten Troonbeeckx[/eluser]
[quote author="wiredesignz" date="1309184883"]
CI_Controller is the regular one. I have not modified the core controller class. MX_Controller stands alone from the CI_Controller core when we use it in HMVC context.[/quote]

If you extend CI_Controller in the context of HMVC, you do end up with a modified version of the original CI_Controller (system/core/Controller.php), don't you?

In CI_Controller::__construct() when the Loader class is instantiated:
Code:
$this->load =& load_class('Loader', 'core');

$this->load is now an instance of MX_Loader (since MY_Loader extends MX_Loader), right?
At the end of the MX_Loader class code (/third_party/MX/Loader.php) there's this line of code:
Code:
(class_exists('CI', FALSE)) OR require dirname(__FILE__).'/Ci.php';

If you would have extended MX_Controller, CI would have already been there, since it was loaded in Base.php.
This is not the case, so CI is instantiated, self::$APP points to the current controller instance and a new MX_Loader is defined.
Code:
...
self::$APP = CI_Controller::get_instance();
        
global $LANG, $CFG;
        
/* re-assign language and config for modules */
if ( ! is_a($LANG, 'MX_Lang')) $LANG = new MX_Lang;
if ( ! is_a($CFG, 'MX_Config')) $CFG = new MX_Config;
        
/* assign the core loader */
self::$APP->load = new MX_Loader;
        
/* autoload module items */
self::$APP->load->_autoloader(array());
...
CI_Controller gets some extended functionality/variables, doesn't it?
That's what I mean with the "non regular" CI_Controller.

So why is this even needed?
If I want to use HMVC, why not just extend MX_Controller?
Maybe this extended functionality for CI_Controller is a fallback option when you forget to extend MX_Controller somewhere?
#19

[eluser]wiredesignz[/eluser]
CI is not designed to allow you to have multiple instances of the CI_Controller class so CI_Controller is extended by the CI class and becomes the application object only in HMVC context. CI holds the CI_Controller instance in Modular Separation simply as a way of allowing the same code base to be used for both. You are correct, to get the full benefit from HMVC you must extend the MX_Controller. But you shouldn't extend (or load) any class if it is not needed?
#20

[eluser]Maarten Troonbeeckx[/eluser]
I think I'm getting it...
Tnx for your replies and patience!

M.




Theme © iAndrew 2016 - Forum software by © MyBB