繁体   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