We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Controllers in 3rd party modules?

Development and Programming

Deep Arora's avatar
Deep Arora
153 posts
15 years ago
Deep Arora's avatar Deep Arora

I understand we can create libraries in 3rd party modules. But what about controllers? Can we?

       
adriankb's avatar
adriankb
2 posts
15 years ago
adriankb's avatar adriankb

There I dont think is any built in support - but we currently have a crude way to do this in the control-panel. Our code needs a review and tidy up (i.e. should use call_user_func_array etc) but I will copy it here for you.

We use extra querystring parameters to determine which controller and method to call.

i.e. The following URL will call our Customer controllers index method, we have already require_onced this controller in our module directory..

http://localhost/system/index.php/index.php?D=cp&C=addons_modules&M=show_module_cp&module=simplicart&method=index&C2=customer&M2=index

Add this method to you mcp.modulename.php file

function __call($method, $args)
    {
        $controller = $this->EE->input->get_post('C2');
        $method = $this->EE->input->get_post('M2');
        $args = array();
        if ($this->EE->input->get_post('A0') !== FALSE)
        {
            $args[0] = $this->EE->input->get_post('A0');
        }
        if ($this->EE->input->get_post('A1') !== FALSE)
        {
            $args[1] = $this->EE->input->get_post('A1');
        }
        if ($this->EE->input->get_post('A2') !== FALSE)
        {
            $args[2] = $this->EE->input->get_post('A2');
        }
        if ($controller)
        {
            $controller_name = ucwords($controller).'_controller';
            $controller = new $controller_name();
        }
        else
        {
            return Dashboard_controller::index();
        }
        
        return $controller->$method((isset($args[0]) ? $args[0] : NULL), (isset($args[1]) ? $args[1] : NULL), (isset($args[2]) ? $args[2] : NULL));
    }

Something similar would work on the front-end.

       
Pascal Kriete's avatar
Pascal Kriete
2,589 posts
15 years ago
Pascal Kriete's avatar Pascal Kriete
I understand we can create libraries in 3rd party modules. But what about controllers? Can we?

Not a lot to go by, but In many ways your control panel mcp file is a controller. We do a handful of things to make that experience more authentic, like modifying the form_validation callbacks to go to the active mcp file.

The frontend is a different beast, of course. Could you tell us what you’re trying to achieve?

       
Deep Arora's avatar
Deep Arora
153 posts
15 years ago
Deep Arora's avatar Deep Arora

In my module (in my signature) we are writing new modules within this module. So, let’s say there are 3 modules A, B, C ..now we can have their respective folders for views and models, but for all these modules, there can be just one “mcp” controller..so the code becomes huge in that one file. For the first module itself the code is already 800 lines, so if we keep on adding modules to EESuite, it will be a nightmere to maintain this one controller file (mcp).

So I am looking for a way to keep all submodules related functionality in their respective folders…

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.