如何在 PyroCMS 上自动创建小部件?
我想开发一个模块作为带有注册表单的活动。事件实际上是一个页面模块,稍微修改一下,添加一些字段,例如注册表单网址。当控制器返回视图时,我希望控制器返回注册表单小部件以及事件信息(文章)和谷歌地图小部件。
想象一个小部件类:
<?php
class Registration_Form_Widget extends Widget{
......
}
我的问题是: 是否可以动态创建小部件(我的意思是小部件实例的创建是动态的(而不是内容),例如使用新的 Registration_Form_Widget 并绕过参数,例如已存储到数据库的注册表单网址?
到目前为止,我从未见过示例展示了如何使用自动增量 ID 动态创建小部件实例,
谢谢...
I'd like to develop a module as an event with registration form. An event is actually a page module with slight modification by adding some fields such registration form url. When the controller return a view, I'd like the controller to return a registration form widget along with the event info (article) and a google maps widget.
Imagine a widget class:
<?php
class Registration_Form_Widget extends Widget{
......
}
My question is:
Is it possible to create widget dynamically (I mean the creation of widget instance is dynamic (not the content) such using new Registration_Form_Widget and bypass the parameter such the registration form url that has been stored to the database?
So far, I never see an example that show how to create widget instance dynamically with automatic increment id
thanks...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,只要您创建小部件,就会创建它们。
Nope, widgets are created whenever you create em.
尽管显然可以通过一些代码来实现它。
没有“神奇功能”可以自动执行此操作,但您可以查看小部件模块文件以了解当用户在管理 CP 中创建小部件时会执行哪些操作。然后你可以自己重现该行为。
Although it is obviously possible to achieve it with a bit of code.
There is no "magic function" to do that automatically, but you can look into the widget module files to understand what is done when a user create a widget in the admin CP. And then you could reproduce the behaviour yourself.