【问题标题】:Joomla 2.5 Plugin onContentSave not workingJoomla 2.5 插件 onContentSave 不起作用
【发布时间】:2016-05-08 09:58:55
【问题描述】:

我想在 Joomla 2.5 中制作一个插件来更改已保存文章的标题。不幸的是它不起作用... onPrepareContent 效果很好,但我想做 onContentSave...

gcm.php

<?php
    defined( '_JEXEC' ) or die( 'Restricted access' );

    class PlgContentGcm extends JPlugin {
        public function __construct(& $subject, $config) {
            parent::__construct($subject, $config);
            $this->loadLanguage();
        }

        public function onContentAfterSave($context, &$article , $isNew) {
           $article->title = "Hello world!";
           return false;
        }
  }
?>

gcm.xml

<?xml version="1.0" encoding="utf-8"?>
<extension version="2.5" type="plugin" group="content">
    <name>plg_content_gcm</name>
    <author>Joomla! Project</author>
    <creationDate>November 2005</creationDate>
    <copyright>Copyright (C) 2005 - 2013 Open Source Matters. All rights reserved.</copyright>
    <license>GNU General Public License version 2 or later; see LICENSE.txt</license>
    <authorEmail>admin@joomla.org</authorEmail>
    <authorUrl>www.joomla.org</authorUrl>
    <version>2.5.0</version>
    <description>DESC</description>
    <files>
        <filename plugin="gcm">gcm.php</filename>
        <filename>index.html</filename>
    </files>
</extension>

也许有人可以帮助我。插件已安装并激活。

【问题讨论】:

    标签: joomla joomla2.5 joomla-extensions


    【解决方案1】:

    调用 onContentAfterSave 并更改标题不会影响保存到数据库的内容:文章已经保存。如果要更改进入数据库的内容,则需要在 onContentBeforeSave 中执行此操作。或者,如果您想在 onContentAfterSave 中执行此操作,您可以使用 UPDATE - sql-statement 手动更新数据库。

    如果你只是想看看是否调用了onContentAfterSave,试试:

    public function onContentAfterSave($context, &$article , $isNew) {
      print_r($article);
      die();
    }
    

    【讨论】:

      猜你喜欢
      • 2013-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-07
      • 2018-02-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多