It's hard for me to describe my situation in English :), hope someone who can understand what I am talking about and do me a favour.
=========== Search Blog: Category: [MYSQL][PHP] <here is drop down list of all cateogries which generated from database> Keyword: _______ [Submit] Search Result: 1. 2. Paginator: <a href="/blog/{cateogry_id}/{page}">[1]</a> [2] =========== I have a page above which list all blog items, at the top of the lists, there is a search form that used for blog searching and filter the results. When I choose a blog category like PHP and post the search form, it will return all lists under that PHP category, the category drop down list also set the category value to PHP and shown PHP label. That's no problem of it at this step. The problem what I met was, when there are so many blogs, I need a paginator, after I click the paginator link, the {cateogry_id} has been set to 2 which is PHP cateogry_id, but for my search form, I still want that category field still make the lable PHP selected. I get the cateogry_id from GET parameter rather than a form which bind Blog Entity. how can I set that cateogry value as I selected? I tried to this: $category = new Cateogry(); $category->setId(2); $blog->setCategory($category); But there an error, it said: Entities passed to the choice field must be managed HERE is my parts code of controller: ================================================ class BlogController extends Controller { /** * Blog List */ public function indexAction($category_id) { $em = $this->get('doctrine')->getEntityManager(); $request = $this->get('request'); $where = array(); $bind = array(); if ($category_id != '') { $where[] = 'pr.category = :category_id'; $bind['category_id'] = $category_id; } // default order by id $orderBy = $request->query->get('orderby') ? $request->query- >get('orderby') : 'pr.id'; // default by ascending $order = $request->query->get('order') ? $request->query- >get('order') : 'ASC'; // paper rate lists $blogs = $em->getRepository('BenefitzDefaultBundle:Blog')- >getBlogsByFields(array( 'orderBy' => $orderBy . ' ' . $order, 'where' => implode(' AND ', $where), 'bind' => $bind )); // search form // ======================================== // Init blog $blog = new Blog(); // i add this, it didn't work and show: // Entities passed to the choice field must be managed $category = new Cateogry(); $category->setId(2); $blog->setCategory($category); // ============================= // Put blog entity to form and get form object $blogType = new BlogType($em); $form = $this->get('form.factory')->create($blogType, $blog, array( 'validation_groups' => array( 'Search' ) )); // If the request method is POST then process the form submitted. if ($request->getMethod() == 'POST') { //print_r($request->request->get('category_id')) $form->bindRequest($request); $where = array(); $bind = array(); if ($blog->getCategory()) { $category_id = $blog->getCategory()->getId(); $where[] = 'pr.category = :category_id'; $bind['category_id'] = $category_id; } $blogs = $em->getRepository('BenefitzDefaultBundle:Blog')- >getBlogsByFields(array( 'where' => implode(' AND ', $where), 'bind' => $bind )); //print_r('a' . $blog->getCategory() . 'a'); } else { } // ========================================= return $this->render('BenefitzAdminBundle:Blog:index.html.twig', array( 'params' => array( 'category_id' => $category_id ), 'form' => $form->createView(), 'blogs' => $blogs, 'orderBy' => $orderBy, 'dispOrder' => $order )); } ======================================================= Here is my Customized Form Type: class PaperRateType extends AbstractType { private $em; public function __construct($em) { $this->em = $em; } /** * (non-PHPdoc) * @see Symfony\Component\Form.AbstractType::buildForm() */ public function buildForm(FormBuilder $builder, array $options) { // category query builder $categoryQb = $this->em->getRepository('Benefitz\DefaultBundle\Entity \Category') ->createQueryBuilder('c'); $builder->add('title', 'text', array( 'required' => false, )); $builder->add('category', 'entity', array( 'required' => false, 'label' => 'Category', 'property' => 'name', 'class' => 'Benefitz\DefaultBundle\Entity\Category', 'query_builder' => $categoryQb )); } ======================================================= Thanks in advance. any help will be greatly appreciated. -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en