首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Joomla2.5插件onContentSave不工作

Joomla2.5插件onContentSave不工作
EN

Stack Overflow用户
提问于 2016-01-30 18:17:22
回答 1查看 51关注 0票数 0

我想在Joomla2.5中制作一个插件,以更改保存的文章的标题。不幸的是它不起作用。onPrepareContent很好,但我想做onContentSave..。

gcm.php

代码语言:javascript
复制
<?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

代码语言:javascript
复制
<?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>

也许有人能帮我。插件已安装并激活。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-30 20:55:21

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

如果您只想查看是否调用了onContentAfterSave,请尝试:

代码语言:javascript
复制
public function onContentAfterSave($context, &$article , $isNew) {
  print_r($article);
  die();
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35105319

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档