Using controllers with library items

Permalink
On some page types I have included an item from the library:
Loader::library('...')
This item includes a form. What would be the best way to attach a controller to this library item? I could add controllers for the page types but I want to avoid duplicate code.

jawbonelid
 
Mnkras replied on at Permalink Reply
Mnkras
so your loading code that will be displayed? that would be an element, not a library,
jawbonelid replied on at Permalink Reply
jawbonelid
OK. So I include an element. Can I attach a controller to it?
Mnkras replied on at Permalink Reply
Mnkras
you can stick logic in an element, but not too much, anything that is in the api can be used by an element, if you are doing db calls, make a model or helper then call those in the element
jawbonelid replied on at Permalink Reply
jawbonelid
Thanks for your help. So, if I was using a controller I would set the form action:

action="<?php echo $this->action('my_function') ?>"

And then detect submission of the form:

if ($this->controller->getTask() == 'my_function')

How would I achieve the same without a controller, does the framework have an elegant way to handle this? Or I do it all manually?