Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search Bundle example is not clear #50

Open
devkbsc opened this issue Oct 9, 2017 · 0 comments
Open

Search Bundle example is not clear #50

devkbsc opened this issue Oct 9, 2017 · 0 comments

Comments

@devkbsc
Copy link

devkbsc commented Oct 9, 2017

Hello,
I have installed this search bundle. I created all the files which are necessary. But the example on the official documentation is not clear to me cause i am newbie to symfony.

here is my source code

Controller

namespace BlogBundle\Controller;

use BlogBundle\Entity\Article;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/**
 * Description of SearchController
 *
 * @author admin
 */
class SearchController extends Controller {

    public function indexAction(Request $request) {
        $search = $request->get('search');
        $em = $this->getDoctrine()->getManager();
        $queryBuilder = $em->getRepository('BlogBundle:Post')->createQueryBuilder('e');
        $filterForm = $this->createForm('BlogBundle\Form\SearchFormType');

        // Bind values from the request
        $filterForm->handleRequest($request);

        if ($filterForm->isValid()) {
            // Build the query from the given form object
            $queryBuilder = $this->get('petkopara_multi_search.builder')->searchForm($queryBuilder, $filterForm->get('search'));
        }

        return $this->render('article/index.html.twig', array(
                    'filterForm' => $filterForm,
        ));
    }

}

Form Type


namespace BlogBundle\Form;

use BlogBundle\Entity\Article;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\Extension\Core\Type\TextType;

class ArticleSearchType extends AbstractType {

    public function buildForm(FormBuilderInterface $builder, array $options) {
        $builder->add('search', MultiSearchType::class, array(
            'class' => 'BlogBundle:Article'
        ));
    }

    public function getName() {
        return 'blog_article_search';
    }

}

View

<div class="col-md-12"  style="border-color:#0b90c4;border-style:solid;padding:25px;margin-bottom:25px;">
        {#{{ render(controller('BlogBundle:Article:list')) }}#}
        {{ form_start(filterForm) }}
        {{ form_rest(filterForm) }}
        {{ form_end(filterForm) }}
    </div>

Did i miss anything else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant