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

[eluser]wiredesignz[/eluser]
The solution for you would be to create a base controller (application/libraries/MX_Conttroller.php) with a layout method available to all your module controllers which then extend the base controller.
Example:
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* Base Controller
*/
class Base_Controller extends Controller
{
    var $data, $autoload = array('model' => array('search_model'));
    
    function layout($tpl) {

        $this->load->view($tpl, $this->data);
    }
}
/* End of file MX_Controller.php */
/* Location: ./application/libraries/MX_Controller.php */

[eluser]Michel-Ange[/eluser]
Great, but complex regarding the simple things my library does.

1. Your modularization solution is really great, but I wish to work WITH it and not to base all my application structure ON it. If all my controllers are depending of ME structure, my solution isn't "with a small footprint" anymore.
2. When doing things like $this->obj->load->view('body', $view_data), I'm not sure it will be interesting to make this library CI independant.

I understand your point of view but understand also that if you want to be CI independant, I wish to be ME independant ! Wink

[eluser]wiredesignz[/eluser]
Any application is only ME independent until you use modules. However the MX_Controller file can be renamed MY_Controller and its contents mostly re-used with basic CI.

Also you need to realize that using multiple instances of the controller class means you cannot use the CI get_instance() function reliably. This fact has bought ME to where it is at present.

EDIT:
Using a base controller is arguably the most powerful feature you can give to your application, so don't count it as a ME only idea. On the other hand loading a library to do something as trivial as you do is truly a waste of resources.

[eluser]Michel-Ange[/eluser]
I answered a little bit fast.
you're right. I will follow your recommandations.

Thanks for you answers.

EDIT : The Layout library don't do only showing views. It was just an example.

[eluser]nearo[/eluser]
[quote author="Sam Dark" date="1225760383"]Useful contribution for MY_Router.
Initial idea by -=ZaRaZa=-.

What's it adds
It adds ability to add routes from within routes.php config located in your module. Global routes.php is still the boss allowing to remap default routes defined in your modules.

Code
Code:
function _set_routing()
{
  //All code below is a copy-paste from CI_Router.
        
  // Load routes from ME modules
  $modules = dir(MODBASE);
  while (false !== ($module = $modules->read())) {
    if($module != '.' && $module != '..'){
      @include(MODBASE.$module.'/config/routes'.EXT);
    }          
  }
  $modules->close();
  
  //End of code addition
  //Following code is a copy-paste from CI_Router.
        
  // Load the routes.php file.
  @include(APPPATH.'config/routes'.EXT);

  //etc.

Hope this will make it's way into ME.[/quote]

Hi Sam, this looks very useful, but I can quite get it to work. Where exactly does it go? I am using CI 1.7 with ME 5.2

So far when using it I get an error saying CI cant find the default route in the routes.php file.

Thank you for your help.

[eluser]Johan André[/eluser]
Maybe my question has been answered earlier in this thread.
It's 34 pages so I takes quite some time to browse it.
Anyway, here goes:

I want to define a Base controller (in MX_Controller.php) which extends "Controller".
I would also want two other controllers extending the Base controller (Frontend and Backend).
My modules controllers then extend either frontend or backend.

It first seem to work just fine. Until I loaded form_validation in my Backend-controller (extended by Base which extended by Controller).

It does not return any errors in form_error() or validation_errors().
It works if I autoload form_validation but it seems kindof dull to autoload a class which is only used in backend controllers.

What might be wrong? Am I overdoing it?

MX_Controller.php:
Code:
class Base extends Controller
    {
        function Base()
        {
            parent::Controller();
        }
        
        function available_to_all()
        {
            // ...
        }
    }
    
    class Frontend extends Base
    {
        function Frontend()
        {
            parent::Base();
        }
        
        function available_only_to_frontend()
        {
            // ...
        }
    }
    
    class Backend extends Base
    {
        function Backend()
        {
            parent::Base();
            $this->load->library('form_validation');
        }
        
        function available_only_to_backend()
        {
            // ...
        }
    }

[eluser]Johan André[/eluser]
[quote author="wiredesignz" date="1240692153"]
Also you need to realize that using multiple instances of the controller class means you cannot use the CI get_instance() function reliably. This fact has bought ME to where it is at present.

EDIT:
Using a base controller is arguably the most powerful feature you can give to your application, so don't count it as a ME only idea. On the other hand loading a library to do something as trivial as you do is truly a waste of resources.[/quote]

Seems like the answer was about two posts up... Smile
Did I understand it correctly? The form_validation class (or actually the form_helper) obviously have trouble finding the validationobject in function form_error().

So in my case I won't be able to use multiple extended controllers?

[eluser]wiredesignz[/eluser]
Modular extensions 5.2.09 is available on the wiki.

Corrected the problem using the from helper with form validation in a module as described above. Thanks Johan Andre. Wink

@johan Andre, Multiple extended controllers does not affect using get_instance() at all.

[eluser]Johan André[/eluser]
[quote author="wiredesignz" date="1241755813"]Modular extensions 5.2.09 is available on the wiki.

Corrected the problem using the from helper with form validation in a module as described above. Thanks Johan Andre. Wink

@johan Andre, Multiple extended controllers does not affect using get_instance() at all.[/quote]

You are a god!
Thanks!

[eluser]Madmartigan1[/eluser]
Hello all,

Sorry to spam, but I felt I may have posted this topic in the wrong thread.

Thanks in advance.
-noob who doesn't read before posting




Theme © iAndrew 2016 - Forum software by © MyBB