Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Database 如何使用自定义插件将值插入Joomla 2.5 DB_Database_Plugins_Joomla_Insert_Components - Fatal编程技术网

Database 如何使用自定义插件将值插入Joomla 2.5 DB

Database 如何使用自定义插件将值插入Joomla 2.5 DB,database,plugins,joomla,insert,components,Database,Plugins,Joomla,Insert,Components,我正在尝试创建一个joomla插件,它将向joomla组件的数据库表中插入一个值。我已经通过Joomla扩展管理器成功构建并安装了该插件,但是当我启用该插件时,我没有看到数据库表中插入的值。下面是我要查看的插件中的php代码: <?php ###################################################################### # Outkast Plugin

我正在尝试创建一个joomla插件,它将向joomla组件的数据库表中插入一个值。我已经通过Joomla扩展管理器成功构建并安装了该插件,但是当我启用该插件时,我没有看到数据库表中插入的值。下面是我要查看的插件中的
php
代码:

<?php
######################################################################
# Outkast Plugin                                                     #
######################################################################

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.plugin.plugin');
jimport( 'joomla.html.parameter');

class plgSystemOutkastplugin extends JPlugin
{
function plgSystemOutkastplugin()
{

$db = JFactory::getDbo();
$name = "http://www.youtube.com/embed/PWgvGjAhvIw?rel=0";

$columns = array('title', 'link_youtube');
$name = "http://www.youtube.com/embed/PWgvGjAhvIw?rel=0";    
$values = array($db->quote('Outkast'), $db->quote($name));

$query->insert($db->quoteName('#__mycomponent_outkastvideos'))
  ->columns($db->quoteName($columns))
  ->values(implode(',', $values));

$db->setQuery($query);
$db->query();

return true;

}        

}
?>

对,我用了一种不同的方法。我使用安装时执行的SQL文件实现了这一点

以下是所有东西的外观:

结构:

file - outkastplugin.xml
file - outkastplugin.php
folder - sql 
  >> file - install.mysql.utf8.sql
<?php

defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.plugin.plugin');
jimport( 'joomla.html.parameter');

class plgSystemOutkastplugin extends JPlugin
{

    function plgSystemOutkastplugin()
    {

    }        

}
?>
CREATE TABLE IF NOT EXISTS `#__mycomponent_outkastvideos` (
        `id` int(10) NOT NULL AUTO_INCREMENT,
        `title` varchar(255) NOT NULL,
        `link_youtube` varchar(255) NOT NULL,

  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;

INSERT INTO `#__mycomponent_outkastvideos` (`title`, `link_youtube`) VALUES ('Outkast', 'http://www.youtube.com/embed/PWgvGjAhvIw?rel=0');
outkastplugin.xml

<?xml version="1.0" encoding="utf-8"?>
<extension version="2.5" type="plugin" group="system" method="upgrade">
   <name>Add Outkast</name>
   <author>My Name</author>
   <creationDate>November 2013</creationDate>
   <copyright>Copyright (C) 2013 All rights reserved.</copyright>
   <license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
   <authorEmail>my@email.com</authorEmail>
   <authorUrl>myURL.com</authorUrl>
   <version>1.7</version>
   <description>This Plugin adds Outkast's Video Hey Ya.</description>

   <files>
      <filename plugin="outkastplugin">outkastplugin.php</filename>
      <folder>sql</folder>
   </files>

   <install>
      <sql>
        <file driver="mysql" charset="utf8">sql/install.mysql.utf8.sql</file>
      </sql>
   </install>

</extension>
我已经通过电子邮件向您发送了完整的邮政包


希望这有帮助:)

嘿,耶!真是太棒了!我看到的唯一一个小问题是,每次我在extensions manager中启用或禁用插件时,插入量都会加倍。所以在初始安装时有一个outkast,启用后有两行outkast。再次禁用将再插入2个,总共4个?知道为什么吗?啊,好的。您想在插件安装时或之后将值插入数据库吗?安装时最好(因为它当前运行)。有没有办法使其在启用或禁用时不会加倍?感谢更新。我已将
调用添加到
xml
描述
下方。我已经清空了
outkastplugin.php
脚本,并根据您的更新将代码移动到
script.php
。现在安装时什么也没发生。可能是b/c吗?我已经从
outkastplugin.php
中删除了代码?可能,保留您所拥有的
outkastplugin.php
文件
CREATE TABLE IF NOT EXISTS `#__mycomponent_outkastvideos` (
        `id` int(10) NOT NULL AUTO_INCREMENT,
        `title` varchar(255) NOT NULL,
        `link_youtube` varchar(255) NOT NULL,

  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;

INSERT INTO `#__mycomponent_outkastvideos` (`title`, `link_youtube`) VALUES ('Outkast', 'http://www.youtube.com/embed/PWgvGjAhvIw?rel=0');