我想在Joomla2.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>也许有人能帮我。插件已安装并激活。
发布于 2016-01-30 20:55:21
调用onContentAfterSave并更改标题不会对保存到数据库的内容产生影响:文章已经保存。如果您想要更改数据库中的内容,则需要在onContentBeforeSave中这样做。或者,如果要在onContentAfterSave中执行此操作,可以使用update -sql-语句手动更新数据库。
如果您只想查看是否调用了onContentAfterSave,请尝试:
public function onContentAfterSave($context, &$article , $isNew) {
print_r($article);
die();
}https://stackoverflow.com/questions/35105319
复制相似问题