代码之家  ›  专栏  ›  技术社区  ›  nimser

symfony插件sfdoctrineactastagableplugin不工作

  •  0
  • nimser  · 技术社区  · 14 年前

    我想将一些标签归因于我的学说模型的一些对象。

    我发现 sfDoctrineActAsTaggablePlugin 这似乎正是我需要的。

    问题是,当我想要保存一个可标记的对象时,我得到了这个错误:

    Unknown record property / related component "saved_tags" on "Mishidea"
    

    MishIdea是我想要标记的类/表的名称。

    以下是我的schema.yml文件的相关部分:

    Mishidea:
      connection: doctrine
      actAs: {Timestampable: ~ , Taggable: ~ }      
      tableName: mishidea
      columns:
        idea_id:
          type: integer(4)
          primary: true
          autoincrement: true
        idea_title:
          type: string()
          notnull: true
          primary: false
        idea_summary:
          type: string()
          notnull: true
          primary: false
        idea_description:
          type: string()
          notnull: true
          primary: false
        idea_up:
          type: integer(8)
          notnull: true
          default: 0
          primary: false
        idea_down:
          type: integer(8)
          notnull: true
          default: 0
          primary: false
        idea_confirmation:
          type: boolean(1)
          default: false
          primary: false
        group_id:
          type: integer(4)
          notnull: false
          primary: false
      relations:
        Mishgroup:
          local: group_id
          foreign: group_id
          type: one
        Ideacomment:
          local: idea_id
          foreign: idea_id
          type: many
        Mishdocument:
          local: idea_id
          foreign: idea_id
          type: many
        RelIdeafollower:
          local: idea_id
          foreign: idea_id
          type: many
    

    我还为类的actas属性尝试了其他类型的语法,例如:

    actAs:
        Timestampable: ~
        Taggable: ~
    

    还有:

    actAs:[Timestampable,Taggable]
    

    但这并不是我所知道的问题:

    $timestampable0 = new Doctrine_Template_Timestampable();
    $taggable0 = new Taggable();
    $this->actAs($timestampable0);
    $this->actAs($taggable0);
    

    in the BaseMishidea.php class of my model.

    我不明白MishIdea类为什么没有获得Taggable类应该添加到它的属性,因为模型似乎通过$this->actas()语句添加了行为。

    如何让这个插件工作?

    如果这有帮助的话,我在mysql/innodb中使用symfony 1.4,我以前也用过postgresql dbms,结果是一样的。

    非常感谢您的帮助。

    谢谢

    杂色燕鸥


    关于johnwards所说的:是否有人可以通过“actas:”,而不是“templates:”确认schema.yml文件中添加了可标记行为?这就是我在这里和那里读到的(见我对约翰沃兹文章的评论),但由于这两个解决方案都不适合我,我不确定。当使用“templates”关键字时,我得到:

    Unknown method Mishidea::addTag
    

    并且不会生成模型的特定类。


    在进一步调查之后,我发现symfony堆栈跟踪是相互关联的。 事实上,当我这样做的时候:

    $idea = new Mishidea();
    $idea->save();
    

    调用taggableListener(下面的堆栈跟踪中的点8),这表明关系正在工作。但是我不明白发生了什么,导致了这个例外。

    堆栈跟踪:

    1. at ()
    in SF_ROOT_DIR/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record/Filter/Standard.php line 55 ...
    
        public function filterGet(Doctrine_Record $record, $name)
    
        {
    
            throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $name, get_class($record)));
    
        }
    
    }
    
    2. at Doctrine_Record_Filter_Standard->filterGet(object('Mishidea'), 'saved_tags')
    in SF_ROOT_DIR/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record.php line 1374 ...
    3. at Doctrine_Record->_get('saved_tags', 1)
    in SF_ROOT_DIR/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record.php line 1333 ...
    4. at Doctrine_Record->get('saved_tags')
    in n/a line n/a ...
    5. at call_user_func_array(array(object('Mishidea'), 'get'), array('saved_tags'))
    in SF_ROOT_DIR/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/record/sfDoctrineRecord.class.php line 212 ...
    6. at sfDoctrineRecord->__call('getSavedTags', array())
    in n/a line n/a ...
    7. at Mishidea->getSavedTags()
    in SF_ROOT_DIR/plugins/sfDoctrineActAsTaggablePlugin/lib/TaggableTemplate.class.php line 93 ...
    8. at TaggableListener->postSave(object('Doctrine_Event'))
    in SF_ROOT_DIR/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record/Listener/Chain.php line 237 ...
    9. at Doctrine_Record_Listener_Chain->postSave(object('Doctrine_Event'))
    in SF_ROOT_DIR/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record.php line 355 ...
    10. at Doctrine_Record->invokeSaveHooks('post', 'save', object('Doctrine_Event'))
    in SF_ROOT_DIR/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Connection/UnitOfWork.php line 112 ...
    11. at Doctrine_Connection_UnitOfWork->saveGraph(object('Mishidea'))
    in SF_ROOT_DIR/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Record.php line 1691 ...
    12. at Doctrine_Record->save()
    in SF_ROOT_DIR/apps/frontend/modules/idea/actions/actions.class.php line 24 ...
    

    If someone wants to see the code for any point of the stack trace (only 1. is expanded here), just ask. 欢迎任何建议。

    3 回复  |  直到 14 年前
        1
  •  2
  •   nimser    14 年前

    呐喊!! 我终于解决了这个问题!

    好。。。The problem is that the sfDoctrineActAsTaggablePlugin plugin does work only for taggable objects which have an id property called precisely "id". I like to put the name of the entity in the name of my properties, that's why I called the idea of my taggable entity "idea_id".

    当我用“id”替换“idea-id”时,一切都像是一个魅力(在schema.yml中,甚至在routing.yml文件中,您可能需要做一些更改)。

    我不知道我是否足够清楚,所以请不要犹豫地问我进一步的解释。

    不管怎样,这对这个插件来说有点丢脸,它还不够通用(将报告给开发人员)。

    顺便说一句,我第一篇文章中所写的actas的所有语法都是等价的,可以使用任何您喜欢的语法。

    Thank you all for your help, each reply was an encouragement without which I wouldn't have had the strength to find the bug ;).

    干杯

        2
  •  0
  •   Jeremy Kauffman    14 年前

    可能的问题:

    确保插件已启用

    ProjectConfiguration::setup ,你应该

    $this->enablePlugins(array(
      'sfDoctrineActAsCommentablePlugin', //plus other plugins, like Doctrine
    ));
    

    正确设置架构

    它应该是这样的:

    ModelClass:
      actAs:
        Taggable:
      columns: //etc
    

    你应该用 actAs templates .

    我不认为你需要为标签设置一个明确的关系,但我可能错了。如果你让我知道,我会编辑这个答案。

        3
  •  -1
  •   johnwards    14 年前

    编辑:是否完成了生成全部重新加载?

    您需要将模板[taggable]添加到您的模式中,而不是actas。

    Mishidea:
      connection: doctrine
      actAs: [Timestampable]    
      templates: [Taggable]  
      tableName: mishidea
      columns:
        idea_id:
          type: integer(4)
          primary: true
          autoincrement: true