M
M
magary42016-12-15 13:27:17
symfony
magary4, 2016-12-15 13:27:17

How to design the following logic?

there is a search page displayed by SearchControllerom
there is a search service itself SearchService::search( $params ) inside which the logic of sorting, pagination and much more other logic is implemented that will be the same for all projects
, the base search parameters will change from project to project
now it's something like this

class SearchController extends Controller
{
    private function getParameterForSearchQuery()
    {
        return [ "type"=>["post","folder","group"], "subtree"=>"events" ]; 
    }

    public function indexAction()
   {
        . . .
        . . .
       $this->render('::index.html.twig',  $this->searchService->search( $this->getParameterForSearchQuery() )  );
   }
}

in short, I made it possible to inherit this controller in subsequent projects and redistribute only one property
getParameterForSearchQuery() { return ["type"=>"file"] }
how much is it right / wrong?
suggest the best practice. patterns etc
thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
voidMan, 2016-12-22
@voidMan

You can put it in a separate bundle, implement it as a service, and put the parameters in the config. Even if some of the functionality in some derivative project is more specific, you can provide for specifying your classes (again in the config) that are inherited from the base controller service.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question