4

对于我正在编写的自定义扩展,我有一个在安装时加载的 ext_tables.sql 文件。

我想在安装例程期间使用 PHP 代码将一些动态数据插入到从 ext_tables.sql 创建的表中。这可能吗?如果是这样,我必须做什么,我必须在哪里做?

或者,是否可以让 PHP 代码在安装期间创建表(使用 DB 接口)而不是依赖于 ext_tables.sql?同样,如果是这样,我必须为此做什么以及我必须在哪里做。

4

2 回答 2

2

Of course you can (with a litte trick):

  1. Add an ext_conf_template.txt to your extension
  2. Add an user-type entry to ext_conf_template.txt

    # cat=basic; type=user[EXT:<EXTNAME>/Path/To/Class.php:Tx_Path_To_Class->postInstall]; label=
    postInstallAction=0
    
  3. Create to PHP-File Class.php in path /Path/To

    This method can be used to do some post install actions or more generally to modify the extension configuration page (The method could return HTML which will be included here).

    class Tx_Path_To_Class {
        /**
         * Generates and returns an message.
         *
         * @param array               $params      Name and value from ext_conf_template.txt
         * @param t3lib_tsStyleConfig $styleConfig Instance of config style editor
         *
         * @return string HTML code
         */
        public function postInstall(array $params, t3lib_tsStyleConfig $styleConfig) {
            // Do your stuff
            return '';
        }
    

    }

I use this to add some user defined output to the configuration page of an extension but you can also you this to execute some initial setup actions.

After installing an extension you can now click on the button "Make updates" to execute your script.

于 2013-03-22T11:54:44.207 回答
0

在旧的 EM 中至少有一个钩子(TYPO3 4.5 及以下)。我想新的也有一些。

您可以将一些字段添加到视图中,您可以在其中设置设置。

$TYPO3_CONF_VARS['SC_OPTIONS']['typo3/mod/tools/em/index.php']['tsStyleConfigForm'][] = "EXT:yourextension/class.yourextension.php:yourextension->main";
于 2012-10-30T13:10:27.640 回答