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

[eluser]wiredesignz[/eluser]
Modules themselves are the building blocks of your application, but, if all you want to do is store libraries in modules and load them from your application/controllers and application/libraries then you have missed the point entirely.

The controller is the entry point for a module... Make it load the libraries or models, perform some task and return the output to the calling controller.

Modules can `talk to each other` using module controller calls.

Thats HMVC.
#62

[eluser]a&w[/eluser]
I was seeing if I could load a shared controller from a module as shown below.

I was able to load all other shared utilities except the controller. Do I have the wrong syntax or is that bad organization anyway?

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

    function YourModule()
    {
        parent::Controller();
    }
    
    function index()
    {        
        $this->load->library('sharedLibrary'); //location: application/libraries/sharedLibrary.php
        $this->load->helper('shared_helper');  //location: application/helpers/shared_helper.php
        $this->load->model('shared_model');    //location: application/models/shared_model.php
        
        //attempt to load a shared controller at: application/controllers/sharedController.php
        $settings = modules::run('sharedController/index'); //looks for: modules/sharedController/controllers/sharedController.php
    }
}

/* End of file yourModule.php */
/* Location: ./modules/yourModule/controllers/yourModule.php */
#63

[eluser]a&w[/eluser]
Sorry, I see that I should have done this:

Code:
function index()
    {        
        //load a shared controller at: application/controllers/sharedController.php
        //run 'index' method by default:
        $settings = modules::run('sharedController');

        //run 'test' method by default:
        $settings = modules::run('sharedController','','test');
    }
}
#64

[eluser]a&w[/eluser]
Should I only use the module controller as an accessor to get access to any module utilities?
I was playing around some more, I thought I might be able to load a helper from another module so I did the following:

Code:
function test()
    {        
        //load a module helper at: someModule/helpers/someHelper.php
        $helper = modules::load('someModule', 'helpers/');
    }
Works good, except modules::load() apparently wants to register it as a class, which a helper is not.

So then I was looking for other ways to load it. I thought maybe load_file(), but it doesn't look like that will work without a 'path'; it doesn't seem to use modules::find() like modules::load() does. If modules::load() did not try to register the helper class (there is none) I think it would have worked fine.

I also tried this with a model:
Code:
function test()
    {        
        //Attempt 1.
        //load a module model at: someModule/models/someModule.php
        $model = modules::load('someModule', models/');
        //it found the model, but doesn't reload it because someModule was
        //already registered (same name as controller already loaded)

        //Attempt 2.
        //so then try to change model filename so same class name isn't loaded:
        //load a module model at: someModule/models/someModule_model.php
        $model = modules::load('someModule/someModule_model', models/');
        /*
          it found the model again, but someModule/models/someModule_model.php
          has this:
         class someModule extends Model
         {
          and I get an error: Class 'Model' not found        
        */
    }
So Attempt 1 and 2 both find there way into the model.
Attempt 1 fails because the class name is already loaded and won't reload.
Attempt 2 fails because it doesn't know where the base class is.
#65

[eluser]wiredesignz[/eluser]
@a&w, modules::load is set up to load and register module controllers, it's more an internal method and shouldn't really be used in your application.
Code:
//preferred method to load a controller from another controller
$this->load->module('someController');

//runs the test method
$settings = $this->someController->test();

//preferred method to load a controller and run 'test' from a view
echo modules::run('someController','','test')
Modular Extensions - PHP5 allows method chaining also
Code:
$settings = $this->module('someController')->test();
#66

[eluser]a&w[/eluser]
[quote author="wiredesignz"]
modules::load is set up to load and register module controllers, it's more an internal method and shouldn't really be used in your application.
[/quote]
Ok. To prevent misuse like I was doing then wouldn't you use private/privileged methods?

[quote author="wiredesignz"]
Code:
//preferred method to load a controller and run 'test' from a view
echo modules::run('someController','','test')

Modular Extensions - PHP5 allows method chaining also
Code:
$settings = $this->module('someController')->test();
[/quote]
Both of those worked just fine.

[quote author="wiredesignz"]
Code:
//preferred method to load a controller from another controller
$this->load->module('someController');//this part ok, loads constructor

$test = $this->load->module('someController');// NULL

//runs the test method
$settings = $this->someController->test();//Call to member function test() on a non-object
[/quote]
That way didn't work, the error on the last line is referenced. I introduced $test just to see what was going on.
#67

[eluser]wiredesignz[/eluser]
Quote:Ok. To prevent misuse like I was doing then wouldn’t you use private/privileged methods?
How would you suggest making a method private and still access it from outside its own class?

Quote:$test = $this->load->module('someController');
Do you want to assign the someController object to $test? thus ending up with two references.

Let me just make this clear... application/controllers are NOT shared assests like application/libraries or application/helpers. application/controllers are also considered module controllers. They are accessible from the URL just like any other module controller.

Controllers are the entry point to your application just the same as in regular CI.
#68

[eluser]a&w[/eluser]
[quote author="wiredesignz" date="1215844044"]
How would you suggest making a method private and still access it from outside its own class?[/quote]
Dunno.

Quote:Do you want to assign the someController object to $test? thus ending up with two references.
No, sorry, didn't mean to confuse the point, adding $test was only added after the error came up as a debugging step.

Quote:Let me just make this clear... application/controllers are not SHARED assests like application/libraries or application/helpers. application/controllers are also considered module controllers. They are accessible from the URL just like any other module controller.
Controllers are the entry point to your application just the same as in regular CI.
Sorry to be so slow on the uptake. Could that statement be expanded to say:

"Controllers are the entry point to your application and modules."
#69

[eluser]wiredesignz[/eluser]
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.
#70

[eluser]mark17[/eluser]
Dear wiredesignz,


My team will start a quite important project early next week. This project has some characteristics which force me to leave pure MVC behind and adopt the HMVC, perhaps even PAC-style, way of development. Although this is not the issue, i do have some concerns of which i hope you to alleviate them.

Somewhere overhere i read some text about ME not working properly when using alternative parents for controllers, the common MY_Controller practice. Although i've found answers to many of my doubts and questions, i cannot quickly redesign an application which does not allow for different parent controllers other than the one provided by CI alone.

I also got the impression from this topic (the PHP5 version) that since a while, there is a way to achieve this. But the question is how to do it and what consequences it implies. Obviously i understand the implications of disemboweling a modular design in which modulecontrollers inherit from one common ancestor, but due to the nature of this project and the all-to-tight deadline i am almost coerced in a situation in which i should't adhere to just my principles Wink

Also, i prefer using a PHP5 version instead. Though it happens to be a rather young rewrite of the original PHP4 ME. I have searched this topic for things like bugfixes etcetera but didn't find much of interest. It also seems that you still keep the PHP5 version for testers-only, which tells me it is not production ready. Can you shed some light on the progress and the expected release of this nice piece of code?

Anyway,i've read tons of material this evening and i hereby excuse for asking for the already-known, so please bear with me.


Regards,




Theme © iAndrew 2016 - Forum software by © MyBB