Pyrocms module or widget or plugin

只谈情不闲聊 提交于 2019-12-10 10:38:13

问题


This is driving me mad! I want to include a simple contact form on a sites homepage. I can't work out if I need to build a module, widget or plugin. None of them seem to be quite right! Modules only seem to work as standalone pages eg the existing contact module. Widgets only seem to display data (got from db or some kind of feed eg twitter) and a plugin seems to be just like a library class. What I need is most like a module. I need a controller (to display the correct view and process the data from the form and views dependent on whether the form has been submitted or not. My problem is I can't work out how to include a module as a section of a page (just like you would a widget) instead of a page in it's own right.


回答1:


Any of those would work.

A module is a MVC triad that can interact with a URL, show views, have its own models, helpers, config, etc. A module is the full meat and two-veg.

A Widget is just a self-contained intelligent partial. That means it takes a few options from the Control Panel for each instance and spits out a chunk of HTML.

A Plugin is just a tag. This tag is used in the template, pages, news, whatever and spits out a chunk of HTML too. A Plugin can have various methods in the class, each method will be a different tag.

I have actually made contact forms as all of these types of addon, but the one I have settled on for PyroCMS v1.1 is a modular plugin. This means there are views, models, etc for the module but we can skip the controller and just make a plugin like so.

That plugin matches up to the tag:

{pyro:contact:form}

That is because it is in the contact module and the method is form. See? :)



来源:https://stackoverflow.com/questions/4935489/pyrocms-module-or-widget-or-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!