[TYPO3-mvc] creating/deleting mm-realations between existing entities in front end?
Uwe Michelfelder
um at limeflavour.com
Tue Feb 16 09:13:50 CET 2010
Hi everyone,
I managed to produce the wished behavior in the blog_example extension.
In the Post-Controller I added:
/**
* addtag action
*
* @param Tx_BlogExample_Domain_Model_Tag $tag
* @param Tx_BlogExample_Domain_Model_Post $post
* @return string The rendered view
*/
public function addtagAction(Tx_BlogExample_Domain_Model_Post $post,
Tx_BlogExample_Domain_Model_Tag $tag)
{
$post->addTag($tag);
$post->setTags($post->getTags()); // is this needed?
$this->postRepository->update($post);
$this->flashMessages->add('Tag was added.');
$this->redirect('show', NULL, NULL, array('post' => $post));
}
To trigger this I use this URL:
index.php?id=XXX&tx_blogexample_pi1[post]=1&tx_blogexample_pi1[tag]=1&tx_blogexample_pi1[action]=addtag&tx_blogexample_pi1[controller]=Post
This works as expexted now. :-)
In my extension however, after the
"$this->groupRepository->update($group);", nothing happens.
Is there any point in the configuration besides TCA, which tells the
Repository where to write the mm-relation.
This is my TCA config for this relation produced by the kickstarter:
[..]
'members' => array(
'exclude' => 0,
'label' =>
'LLL:EXT:mmtest/Resources/Private/Language/locallang_db.xml:tx_mmtest_domain_model_group.members',
'config' => array(
'type' => 'select',
'size' => 10,
'minitems' => 0,
'maxitems' => 9999,
'autoSizeMax' => 30,
'multiple' => 1,
'foreign_table' => 'tx_mmtest_domain_model_member',
'MM' => 'tx_mmtest_group_member_mm',
)
),
[..]
And the add action of my ext:
/**
* addmember action
*
* @param Tx_Mmtest_Domain_Model_Group $group The group the member joins
* @param Tx_Mmtest_Domain_Model_Member $member The member
* @return string The rendered view
*/
public function addmemberAction(Tx_Mmtest_Domain_Model_Group $group,
Tx_Mmtest_Domain_Model_Member $member)
{
$group->addMember($member);
$group->setMembers($group->getMembers());
$this->groupRepository->update($group);
echo "member added";
exit;
}
If someone wants to have a closer look into this, I put a zip file of
the ext here:
http://tinyurl.com/yfrue4a (DropBox)
Greetings,
Uwe
Am 15.02.10 19:06, schrieb Uwe Michelfelder:
> Hello all,
>
> we encounter problems while trying to create a MM-relation between
> existing entities.
>
> We already have GROUPS and MEMBERS which can join or leave groups.
> Both entities do already exist, so the members don't come along while
> creating/editing the group entity via a form.
>
> What we do is, that we trigger the joinAction with a link which provides
> the current selected group object. In the controler action the current
> fe-user is selected.
>
> We now have both objects "group" and "member".
>
> According to the blog_example -> adding tags to the post, it would go
> like this:
> The group model knows has the "addMember" method including the
> attach-Method on $members (initialized in the constructor).
>
> The difference to our code is, that tags are only addable through the
> Typo3 backend.
>
> Is there no way to create MM-relations in the front end controller?
>
>
> Greetings,
> Uwe
More information about the TYPO3-project-typo3v4mvc
mailing list