我想将一些标签归因于我的学说模型的一些对象。
我发现
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.
欢迎任何建议。