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
2 controller files in one module
4 years ago
4 years ago
#1
4 years ago
#2
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
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
4 years ago
#3
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.
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.
4 years ago
#4
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
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
4 years ago
#5
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"
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"
4 years ago
#6
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
Gavin, I would have actually split the answer to 2 winners. Yours is very Philosophical. I like it.
Thanks Everyone,
Dan
4 years ago
#7
Yep, that's 100% cool. Simon actually answered the question and David and I supplied the supporting theory. ?