Php Symfony插件sfdoctrineatastaggableplugin不工作
我想给我的条令模型的一些对象赋予一些标签 我发现这似乎正是我所需要的 问题是,当我想保存一个可标记对象时,会出现以下错误:Php Symfony插件sfdoctrineatastaggableplugin不工作,php,plugins,symfony1,doctrine,Php,Plugins,Symfony1,Doctrine,我想给我的条令模型的一些对象赋予一些标签 我发现这似乎正是我所需要的 问题是,当我想保存一个可标记对象时,会出现以下错误: Unknown record property / related component "saved_tags" on "Mishidea" Mishidea是我想要标记的类/表的名称 以下是my schema.yml文件的相关部分: Mishidea: connection: doctrine actAs: {Timestampable: ~ , Taggabl
Unknown record property / related component "saved_tags" on "Mishidea"
Mishidea是我想要标记的类/表的名称
以下是my 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: ~
以及:
但这不是我得到的问题:
$timestampable0 = new Doctrine_Template_Timestampable();
$taggable0 = new Taggable();
$this->actAs($timestampable0);
$this->actAs($taggable0);
在我的模型的BaseMishidea.php类中
我不明白为什么Mishidea类没有得到标记类应该添加到它的属性,因为模型似乎通过$this->actAs()语句添加了行为
如何让这个插件工作
如果这有帮助的话,我将Symfony 1.4与MySQL/InnoDB一起使用,我以前也曾尝试过PostgreSql DBMS,结果是一样的
非常感谢你的帮助
谢谢
毛茸茸的
EDIT1-关于johnwards所说的:有人能确认标记行为是通过“actAs:”而不是“templates:”添加到schema.yml文件中的吗?这是我在这里和那里读到的(见我在约翰沃兹的帖子上的评论),但由于这两种解决方案都不适合我,我不确定。使用“模板”关键字时,我得到:
Unknown method Mishidea::addTag
并且不会生成模型的特定类
EDIT2-经过进一步调查,我发现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 ...
如果有人想查看堆栈跟踪的任何一点的代码(这里仅扩展了1),只需询问。
欢迎您提出任何建议。编辑:您是否完成了构建所有重新加载? 您需要将模板:[Taggable]添加到架构中,而不是添加到actAs中
Mishidea:
connection: doctrine
actAs: [Timestampable]
templates: [Taggable]
tableName: mishidea
columns:
idea_id:
type: integer(4)
primary: true
autoincrement: true
可能的问题:
确保已启用插件
在ProjectConfiguration::setup
中,您应该
$this->enablePlugins(array(
'sfDoctrineActAsCommentablePlugin', //plus other plugins, like Doctrine
));
正确设置架构
应该是这样的:
ModelClass:
actAs:
Taggable:
columns: //etc
您应该使用actAs
而不是模板
我不认为需要为标记设置显式关系,但我可能错了。如果您让我知道,我将编辑此答案。哇哇!!
我终于解决了这个问题
嗯。。。问题在于,SFdoctrineAttasTaggablePlugin插件仅适用于具有精确称为“id”的id属性的可标记对象。我喜欢将实体的名称放在属性的名称中,这就是为什么我将可标记实体的想法称为“idea_id”
一旦我将“idea_id”替换为“id”,一切都像一个符咒一样工作(您可能需要在schema.yml中做一些更改,甚至稍后在routing.yml文件中也可能会做一些更改)
我不知道我是否足够清楚,所以请不要犹豫,问我进一步的解释
无论如何,这对于这个插件来说有点丢脸,它不够通用(将向开发人员报告)
顺便说一句,我在第一篇文章中写的actAs的所有语法都是等价的,用你喜欢的那个
谢谢大家的帮助,每一个回复都是一种鼓励,没有这种鼓励,我就没有力量找到bug;)
干杯谢谢约翰沃德,但你确定吗?这确实是写在官方文档上的内容(见我第一篇文章中的链接),但一些消息来源说文档是错误的,我们应该使用“actAs”,而不是“模板”。(,)如果我听从你的建议,原则是:构建——一切正常(和以前一样),但当我使用一个可标记函数时,我得到了:未知方法Mishidea::addTag任何想法?我只是根据文档中的答案。您是否在代码中搜索了保存的_标记以查看调用位置?保存的_标记仅存在于插件的TaggableTemplate.class.php中。我刚刚编辑了我的原始帖子,添加了我得到的堆栈跟踪的一部分。这证明了这段关系是有效的,但我不明白到底出了什么问题。如果这个堆栈跟踪启发了你,请随意分享你的灵感:-)我打赌你只是检查了一下,你已经完成了构建所有的重新加载?是的,我做了,而且在我看来确实由于某种原因模型与我的数据库不匹配。。。这看起来很奇怪,因为我用两个不同的DBMS(postgres和mysql)尝试了几十次这个操作,每次都执行“symfony原则:构建——全部——并加载…”-/
ModelClass:
actAs:
Taggable:
columns: //etc