有没有办法为 Joomla 中的 com_content 等现有组件创建自定义模型/视图?
有没有办法为现有组件创建自定义模型/视图?例如,如果您想更改 com_content 中使用的查询以在查看类别时包含其他表中的数据,是否可以创建一个新的模式/视图来实现此目的?或者,如果想要集成其他类型的内容(例如使用 twitter api 或 tumblr api)以将内容放入类别流中(并保持正确的分页),则需要更改模型,但是可以在不进行黑客攻击的情况下创建自定义模式吗Joomla 核心?
谢谢!
Is there a way to create a custom model/view for an existing component? For instance, if you wanted to change the Query used in com_content to include data from other tables when looking at a Category, is it possible to create a new modal/view to make this happen? Or if one wanted to integrate other types of content (like using the twitter api or tumblr api) to put contentment in the category flow (and maintain the correct pagination) it would require change the model, but can a custom modal be created without hacking the Joomla core?
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
joomla 不提供任何功能来创建现有组件的自定义模型或视图。
您可以使用模板覆盖来覆盖视图,但它只会更改页面的外观,但不会更改功能。
joomla doesn't provide any feature to create custom model or view of an existing component.
you can override a view using template overriding but it will only change the look of the page but not the functionality..
创建内容时,我们编写了一个执行 onAfterContentCreate 的插件,在这个插件中我们编写了自定义模型功能。当所有默认功能都已执行时,将调用此插件。我们修改了模板中的视图,在模板 html 文件夹中我们编写了扩展视图。
When creating content we have written a plugin which executes onAfterContentCreate in this plugin we have written custom model functionality. This plugin gets called when all the default functionality have executed. We have modified the view in our template, In template html folder we have written extended view.
正如 sushil bharwani 指出的那样,最好的选择可能是创建内容插件并连接 onAfterContentCreate 事件(请参阅 可用内容插件的事件)。
也可以按照您最初的意图将组件模型用于您自己的扩展。此方法已在 Joomla CMS 1.7 本身中使用(mod_articles 模块在自己的帮助程序文件中加载内容组件模型),类似于此处精彩文章中的描述:Joomla MVC – 从任何地方加载模型!。
我可以确认这工作正常,但评估哪个选项更适合您的项目,因为组件模型主要是为 Joomla 的本机组件制作的,并且可能缺少一些特定的功能。
As sushil bharwani pointed out, probably best option is to create Content plugin and hook up the event onAfterContentCreate (see available events for content plugins).
It's also possible to use components models for your own extension as you initially intended. This method has been used in Joomla CMS 1.7 itself (mod_articles modules load content component model in own helper files), similar as described in great article here: Joomla MVC – Load a model from anywhere!.
I can confirm this works fine, but evaluate which option is better for your project as component models are made primarily for Joomla's native components and may lack some specific functionality.