Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6995051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:58:18+00:00 2026-05-27T19:58:18+00:00

I have setup a Symfony 2 Data Transformer that will allow the user to

  • 0

I have setup a Symfony 2 Data Transformer that will allow the user to enter a comma separated list of string and convert that to an ArrayCollection which Doctrine expects. Now the problem is in the transform() where it will convert an ArrayCollection to a comma separated string.

/**
 * Transform ArrayCollection of Tag's into Comma Separated string
 * 
 * @param ArrayCollection $tags
 * @return string
 */
public function transform($tags) {
    if ($tags == null) 
        return '';

    $tagNames = array();
    var_dump($tags);
    $tags->map(function($tag) use(&$tagNames) {
        $tagNames[] = $tag->getName();
    });
    return implode(', ', $tagNames);
}

$tags look like:

object(Doctrine\Common\Collections\ArrayCollection)#222 (1) {
  ["_elements":"Doctrine\Common\Collections\ArrayCollection":private]=>
  array(1) {
    [0]=>
    array(1) {
      [0]=>
      object(JM\BlogBundle\Entity\Tag)#53 (3) {
        ["id":"JM\BlogBundle\Entity\Tag":private]=>
        int(1)
        ["name":"JM\BlogBundle\Entity\Tag":private]=>
        string(4) "blog"
        ["description":"JM\BlogBundle\Entity\Tag":private]=>
        string(0) ""
      }
    }
  }
}

Notice its an array in an array. Why is that?

UPDATE: data transformer code -> http://pastie.org/3004780

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:58:18+00:00Added an answer on May 27, 2026 at 7:58 pm

    It looks like in your reverseTransform() method, you’re searching for a single tag with this line:

    $tag = $this->em->getRepository('JM\BlogBundle\Entity\Tag')->findBy(array('name' => $strTag));
    

    However, findBy() will always return an ArrayCollection, even if only one result is found. Try using findOneBy(), which will simply return the result without the ArrayCollection wrapper.

    Also, for some prior art, check out the FPNTagBundle and Taggable Doctrine Extension. In particular, the TagManager might have some optimizations that you can implement in your own code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have setup tinymce in a webpage for users to generate html data that
I have symfony 1.4 installed and had setup my own user model (table). Now,
Entities in symfony 2 have doctrine tags that are preceded with @ORM\ (eg @ORM\Entity).
I have been trying to setup Symfony2 on Windows so that I can use
I have this setup in my symfony application: # settings.yml prod: .settings: no_script_name: true
I have setup a process in my User model to send a bunch of
I have a symfony website running on the standard LAMP setup. I need to
I have setup web dav on windows server 2008. It seems to work fine
I have setup a property and implement INotifyPropertyChanged like so... public event PropertyChangedEventHandler PropertyChanged;
I have setup svnserve and for now now I am testing a repository with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.