Multiple actions for a controller
I am hoping that someone can shed some light on exactly how MVC works in C5 - at the moment I am lost and convinced it doesn't really use MVC at all.
I have a controller, call it feed, this lists some rss feed. I then have an add and edit controller, each with their own view script of the same name. The feed controller is called controller.php and it uses view.php.
Now, I want a new action for the feeds controller, called items. This action will show all the items for a feed, an ID will need to passed along.
How do I set up a new action, called items inside controller.php and point it at a new view for items?
At the moment I can only see how to create controller after controller with view after view, without actually using a controller correctly for multiple actions. It seems like there is one action per controller?
Please can someone help me and tell me this isn't true!
I have attempted to use (the poorly documented) action_*() method, but this seems to be for AJAX and doesn't give me the option to use a view for the "action".
1) You're right, it's a partial implementation of MVC.
2) view.php is the only view you get. You'll have to fake it with conditionals in view.php (you can mitigate this somewhat by including an 'elements' file to do the rendering for you), or redirect to a new page with a PageType that does what you want.
3) The action_* thing put me on the wrong path for a few hours too. It is either a red herring or perhaps a relic of prior versions of C5. Any resource appended to the base URI will be invoked as a controller method. E.g., if you POST to /my/silly/resource/createNewFooBaz, then the system will load the Page which is bound to "/my/silly/resource" and look for a method named "createNewFooBaz" on that Page's controller. From there, you do whatever you want, and by default, the view will be instantiated for that page. The bottom of the controller method where I've done my redirects.
xaritas, on point #2 you aren't entirely correct. This isn't at all well documented, but you can have different views for each action.
See my screenshot.
Basically inside of each controller inside of each action you can render a different view, in my case in the "edit" action of the controller that wires up to a view you can call in my case $this->render('/dashboard/page_mapper/manage/edit');
so you don't need a ton of conditionals built on top of $this->controller->getRequestTask() or anything like that.
arrestingdevelopment, i'd recommend setting an array from a controller and rendering a chunk of html foreach via a concrete5 element in the view in a foreach.
This is similar to what I ended up doing, I use
To be honest this has amazed me, this approach, its not MVC at all. It awful and makes a joke of coding for the backend of C5. It's a shame that we need to hack the code together to make it more like MVC, or create an endless stream of files to accommodate it's lack of support for MVC.
I guess it would be nice to have it wire up, but to automatically wire up wouldn't necessarily be ideal.
If you wanted you could probably VERY easily add this kind of behavior to concrete5 if you just submit a pull request for concrete5 on github.
The fact that you can do it in the way we are isn't IMO widely known, especially from looking at some of the other marketplace items, so you're already ahead of the curve.
If I'm way off base... my bad!