Web应用程序上的小部件
I am writing a webapplication which will have widgets like iGoogle does (but with different information ;)). Since there will be different colomns I would love to hear your ideas on how to call the modules in the code. I want to define in the database what widgets are enabled and in what column they are and in what order they should appear. I am working with PHP and the Zend Framework. Is there any good practice to add the widgets?
I was thinking of doing it like this: You save the widgets name and there would be a folder with widgets in them and with require_once I would include the file and execute a default command like:
echo ExampleWidgetClass::run();
我正在编写一个web应用程序,它将具有像iGoogle一样的小部件(但具有不同的信息;))。 由于会有不同的colomns,我很想听听你如何在代码中调用模块的想法。 我想在数据库中定义启用哪些小部件以及它们在哪个列中以及它们应该以何种顺序出现。 我正在使用PHP和Zend Framework。 添加小部件是否有任何好的做法? p>
我正在考虑这样做: 您保存小部件名称,并且会有一个包含小部件的文件夹和require_once I 将包含该文件并执行默认命令,如: p>
echo ExampleWidgetClass :: run();
code> pre>
div>
Your approach sounds reasonable: insist on a well-defined interface for each widget, and then invoke that method (or those methods) for each registered widget. Some things to keep in mind:
- abstraction: do the widgets know where they are on the page, or how big their window is?
- security: are the widgets written by 3rd parties? do you trust them? does their output need to be escaped or sanitized?
- backend: some widgets may need to make backend calls to get data. consider how they request backend calls be made in a batch before the page is rendered. dispatching multiple backend requests (such as sql queries) simultaneously can yield better page performance than querying sequentially.
What kind of confirmation are you looking for from us? If it's your system, your widgets, then just run them the way you think is best ?
What you describe sounds a lot like a solid setup. Just go for it I'd say and not ask StackOverflow? :-P
Depending on what you are trying to achieve for your users, you may also want to consider external widget specifications like W3C Widgets (Apache Wookie) or OpenSocial Gadgets (Apache Shindig)