簡體   English   中英

自定義組件中的joomla 3.x標簽失敗

[英]joomla 3.x tags in custom component fails

運行Joomla 3.3.0-dev

我正在關注此處發布的有關向第三方組件添加標簽支持的信息。

我已將內容類型添加到#__content_types表中, #__content_types所示修改了我的table文件:

class MycomponentTableElement extends JTable
{
    public $tagsHelper = null; // failed when protected and public

    public function __construct(&$_db)
    {
        parent::__construct('#__mycomponent', 'id', $_db);
        // Add Joomla tags
        JObserverMapper::addObserverClassToClass('JTableObserverTags', 'MycomponentTableElement', array('typeAlias' => 'com_mycomponent.element'));
        //$this->_observers = new JObserverUpdater($this); JObserverMapper::attachAllObservers($this); // failed with or without this line  
    }

我在edit模板中添加了標簽字段,並且效果很好-但是當我保存對象時,出現以下錯誤:

Save failed with the following error: Unknown column 'tagsHelper' in 'field list'

我想念什么? 沒有提到其他步驟(除了前端步驟!)。 似乎我需要修改模型,但該信息不適用。

謝謝

此頁面需要復制編輯 ”,的確如此!

我還按照頁面中所述執行初始步驟

  • 為擴展視圖注冊“內容類型”
  • 將“觀察者方法”添加到擴展表類
  • 將“標簽字段”添加到擴展名編輯表單

但是要使field標簽在自定義擴展上起作用,我需要在后端的視圖文件中顯式設置form字段值:

$tagsHelper = new JHelperTags;

$this->form= $this->get('Form');

$this->form->setValue('tags', null, $tagsHelper->getTagIds( $this->item->id, 'com_custom.viewname') );

這樣,編輯頁面上的所有內容似乎都可以正常工作..確實存在更好,更干凈的方法,但是直到doc頁面不會更新之前,這可以幫助某個人!

1-將標簽字段添加到您的xml表單文件或編輯模板文件

2-修改#__content_types表文件:

function __construct(&$db)
    {
        parent::__construct('#__ir_products', 'id', $db);
        JTableObserverTags::createObserver($this, array('typeAlias' => 'com_itemreview.product'));
    }

3-修改模型文件的getItem函數:

public function getItem($pk = null)
    {
        $item = parent::getItem($pk);

        if (!empty($item->id))
        {
            $item->tags = new JHelperTags;
            $item->tags->getTagIds($item->id, 'com_yourcomponent.yourmodel');
        }
        return $item;
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM