2014-07-02 56 views
1

我知道這裏有很多問題,但是我已經通過解決方案找到了所有找到的問題,但都無法解決我的問題。onContentBeforeSave和onContentAfterSave沒有觸發

保存來自前端和後端的文章時,onContentBeforeSave和onContentAfterSave事件都不會觸發。 同一插件中的onContentBeforeDisplay事件正常工作。

這是我的代碼,你有什麼想法嗎?謝謝。

<?php 
// no direct access 
defined('_JEXEC') or die('Restricted access'); 
jimport('joomla.plugin.plugin'); 

class plgContentBillrepeat extends JPlugin { 
     /** 
     * Load the language file on instantiation. Note this is only available in Joomla 3.1 and higher. 
    * If you want to support 3.0 series you must override the constructor 
    * 
    * @var boolean 
    * @since 3.1 
    */ 
    protected $autoloadLanguage = true; 

    /** 
    * Plugin method with the same name as the event will be called automatically. 
    */ 

    function onContentBeforeSave($context, &$article, $isNew) { 
      JError::raiseNotice(100, 'onContentBeforeSave plugin fired!'); 
      return true; 
    } 

    function onContentAfterSave($context, &$article, $isNew) { 
      JError::raiseNotice(100, 'onContentAfterSave plugin fired!'); 
    } 

    function onContentBeforeDisplay($context, &$article, &$params, $limit=0) { 
      JError::raiseNotice(100, 'onContentBeforeDisplay plugin fired!'); 
      return ""; 
    } 
} 
?> 

回答

2

解決了通過傳遞值的文章而不是通過引用的問題。

這似乎工作:

function onContentBeforeSave($context, $article, $isNew) { 
      JError::raiseNotice(100, 'onContentBeforeSave plugin fired!'); 
      return true; 
    } 

    function onContentAfterSave($context, $article, $isNew) { 
      JError::raiseNotice(100, 'onContentAfterSave plugin fired!'); 
      return true; 
    } 

雖然我也不太清楚爲什麼,因爲所有的文件清楚地表明文章應該按引用傳遞,甚至我在這裏看到的問題表明,路過的價值導致事件不會被觸發。

+0

我假設這是一個內容插件,你會不會添加你用於未來參考的Joomla版本? –