wanze/TemplateEngineFactory

Controller as a (proper) class

thepurpleblob opened this issue · 2 comments

This is probably a bit of a silly question. But, here we go anyway...

It makes me really uncomfortable that the 'controller' is not a proper class. It's just a snippet of inline code. Can you think of anyway that (say) template/home.php could load a class (e.g. 'class HomeController {...)?

Just thinking aloud.

wanze commented

There are no silly questions :)

It makes me really uncomfortable that the 'controller' is not a proper class. It's just a snippet of inline code. Can you think of anyway that (say) template/home.php could load a class (e.g. 'class HomeController {...)?

This is how ProcessWire works - it maps the request to a PHP file in site/templates and executes whatever logic is defined there. You are free to use a class, e.g. create a HomeController and put your logic in there. This module is not so much about the "Controller" part in the MVC pattern but more about the "View" part, allowing to delegate the rendering to a template engine.

Does this answer your question somehow? Maybe I could provide some ideas/snippets if you can describe your desired use case in more detail.

Yes it does - thanks.

I think I may just be a little prejudiced against "inline" code like this. I'll have a think :)