简体   繁体   English

为Joomla3组件创建虚拟内容

[英]Creating dummy content for Joomla3 component

I'm creating Joomla3 component and I need to create some dummy content during the installation, I know that I can use sql file to fill the tables, but this works mainly for custom created tables specific for my component. 我正在创建Joomla3组件,并且需要在安装过程中创建一些虚拟内容,我知道我可以使用sql文件填充表,但这主要适用于针对我的组件的自定义创建的表。 Problem arises when I want to add something to the #__content table, the 'alias' column isn't considered as unique and there can occur duplicate entries, if someone tries to install the component several times. 当我想向#__content表中添加某些内容时出现问题,“别名”列不被认为是唯一的,并且如果有人尝试多次安装该组件,则可能会出现重复的条目。 I would like to know what is the best way to insert a record into #__content table without worrying about collateral damage like duplicate entries. 我想知道什么是将记录插入#__content表的最佳方法,而不必担心诸如重复项之类的附带损害。 Thanks all ! 谢谢大家!

Solution 1 : You can use INSERT IGNORE so that while installing extension multiple times there will be no concern of duplicate entries. 解决方案1:可以使用INSERT IGNORE以便在多次安装扩展程序时,无需担心重复条目。

Solution 2 : In Joomla there is a provision of script file which a component can have. 解决方案2:在Joomla中提供了组件可以具有的脚本文件。

So, when an extension is installed/update/uninstall joomla triggers or calls certain predefined function like install, update, preflight, postflight etc available in the extension script file. 因此,在安装/更新/卸载扩展程序时,joomla会触发或调用扩展脚本文件中可用的某些预定义功能,例如安装,更新,预检,后检等。

You can add install method in your extension script and execute this sql file on this method so that this will not be called on extension update case 您可以在扩展脚本中添加install method ,并在此方法上执行此sql文件,以便在扩展更新时不会调用该方法

Solution 3 : You can maintain a separate table in your database for this task and when you perform this dummy content creation you can mark this in your DB and further you can check whether this step has already done or not before initiating dummy content creation so that when someone install this extension multiple times this checking will prevent the same task to execute again and again. 解决方案3:您可以在数据库中为此任务维护一个单独的表,并且在执行此虚拟内容创建时,可以在数据库中对此进行标记,此外,您可以在启动虚拟内容创建之前检查此步骤是否已经完成,以便当有人多次安装此扩展程序时,此检查将阻止同一任务一次又一次地执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM