Open Ronin-0822 opened 2 months ago
Yeah, the MainPageController might get pretty large. I'm in favor of a separate Controller for every page with an index() action. Can we try that?
In Node, a common approach is a "controllers" directory with controllers separated by category. For example, there might be a controller/userController.js that contains all the functionality to run when the http://localhost/user route is accessed.
Yeah, I was leaning towards the separate Controller for every page, too. Let's take that approach then.
In PHP there's a thing called 'namespaces', which allows class files being organized into directories. So, even within the Controllers we could have some subdirectories to categorize the class files even further (usually only 1 or 2 folders down). This also solves the problem of name collisions or extra long classnames.
That makes sense. I will try to create some routes.
new routes are created in the
routes.php
file like this:$router->addRoute('/route', Controller, action)
The router gets a uri and calls the corresponding action.
So in case of a static route (no parameters sent) for an 'about' page...
$router->addRoute('/about', AboutController::class, 'index'
How we want to structure the controllers is up to us. We could have a separate Controller for every page with an
index()
action, or have aMainPageController
with actions for every page:So, it's basically a choice between multiple small controllers, or a single controller that might get very big.
Oh, actually, we could have just a
PageController
that takes a$page
parameter.That's something I'm struggling a lot with at the moment, how to best structure and architect applications. What business logic goes into what Model/Controller...