1127

2 controller files in one module

Comments for “2 controller files in one module”
 

Posted by djnordeen on Tuesday 22nd February 2022 at 02:59 GMT

How do you call another controller file in the same module
Example
Cars Module
--controllers/cars
--controllers/parts

Or do you use a sub module ?
Cars
--controller/cars.php
--Parts
----controllers/Parts.php

How would you reference the controller files in each scenario?
Thanks, Dan
Early Adopter

djnordeen

User Level: Early Adopter

Date Joined: 20/08/2021

Posted by DaFa on Tuesday 22nd February 2022 at 23:35 GMT

Hi Dan,

I could be wrong but I don't think having multiple controllers in the same module would work. I did read somewhere in the docs it is theoretically possible but not recommended.

I'd stick with super modules > https://trongate.io/docs_m/information/complete-video-tutorial and the written docs https://trongate.io/docs_m/information/what-are-super-modules-and-sub-modules. I also put a link showing how to quickly create them using the VSCode extension on Jake's YT channel.

and don't forget the MODULE_ASSETS_TRIGGER in the config.php
define('MODULE_ASSETS_TRIGGER', '_module');
Founding Member

DaFa

User Level: Founding Member

Date Joined: 30/11/2018

Posted by Davcon on Wednesday 23rd February 2022 at 00:07 GMT

I'll give this one a shot but I don't think I can offer an answer any better than Simon's.

Nevertheless, here's my two cents:

For a very long time I - and many others with me - used to participate in debates about how best to use MVC. There are lots of articles preaching about things like 'fat model / thin controller' whilst guys like me would argue for things like 'fat controllers / thin models'.

What I came to realise - very recently - is that none of it really matters.

For example, regardless of whether you're a fat controller or a thin controller guy - the code isn't going away. It's just moving from one part of your app to another. So, nobody is really 'solving' anything here. We're all just shuffling code from one place to another and pretending that we're smart for doing so.

Of course, this has nothing whatsoever to do with your question. However, I'm going to attempt to step back and throw a very general concept at you. That's because, to me it's all just semantics. Even at the best of times, developers can't always agree on how to use the different parts that make up M, V and C. So, why even bother?

What is a controller?

If it's a class then including an additional PHP class in that folder (either using include() or require()) should be no big deal. If a controller is just a file that acts as an intermediary between view files and databases then... cool... use include() or require(). Nothing has changed.

The point is... all roads lead to bullschitt.

It's just words that somebody made up in a futile attempt to describe what is going on. Don't dwell on it.

As always, the correct answer is always the one that feels good for you. You have an inner genius. Listen to your inner genius. You're the best developer in the world. The answer that YOU decide to be the best... IS the best. When it comes to development, you are the boss.

This comment was edited by Davcon on Wednesday 23rd February 2022 at 00:08 GMT

Founding Member

Davcon

User Level: Founding Member

Date Joined: 3/11/2018

Posted by djnordeen on Wednesday 23rd February 2022 at 00:42 GMT

Thanks Simon,
I set it up with the second file structure.
I'll look into the assets method.

David, You are right about either. Either way has the same amount of code. Maybe one has less folders. But in the end the Module with the Sub-Module worked for the Mailman Module.

Thanks,
Dan

This comment was edited by djnordeen on Wednesday 23rd February 2022 at 01:34 GMT

Early Adopter

djnordeen

User Level: Early Adopter

Date Joined: 20/08/2021

Posted by D3mon on Wednesday 23rd February 2022 at 11:08 GMT

You didn't hear it from me but here's my worthless 2p:

The 'model' is just another controller. All code is a 'controller' - it facilitates the flow of data from one place/form to another.
MVC is just a construct - a theory on how it all works out for the best 'in the end' - bit like a religion. Have a little prayer now and then by all means but when you find yourself stoning people to death in the street, it's probably gone too far.
The best advice you'll get anywhere on any given topic is: Take what resonates and leave the rest.

"We are the music makers, And we are the dreamers of dreams"
Level One Member

D3mon

User Level: Level One Member

Date Joined: 6/07/2021

Posted by djnordeen on Wednesday 23rd February 2022 at 13:31 GMT

I gave Simon the Star because it is the closest answer. I liked his suggestion at the bottom.
Gavin, I would have actually split the answer to 2 winners. Yours is very Philosophical. I like it.
Thanks Everyone,
Dan
Early Adopter

djnordeen

User Level: Early Adopter

Date Joined: 20/08/2021

Posted by D3mon on Wednesday 23rd February 2022 at 15:16 GMT

Yep, that's 100% cool. Simon actually answered the question and David and I supplied the supporting theory. 👍

This comment was edited by D3mon on Wednesday 23rd February 2022 at 15:16 GMT

Level One Member

D3mon

User Level: Level One Member

Date Joined: 6/07/2021

×