M
M
Michael2015-03-02 15:46:51
symfony
Michael, 2015-03-02 15:46:51

Routing. How to remove nesting levels?

there are links like
site.loc/catalog/ees/catalogGroup-31177
site.loc/catalog/bbs/catalogGroup-31232/catalogGroup-31
site.loc/catalog/bvs/catalogGroup-3232/catalogGrou...
here is the route for these pages :

_auto:
    pattern: /{url}
    defaults: { _controller: SiteRsrSecurityBundle:ContentTypes:loadUrlPage }
    requirements:
        url: ".+"

Here is the method from ContentTypesController
public function catalogGroupType(Page $page)
    {
        $childGroups = $this->getContentService()->getListPages($page->getId(), new PageFilter('catalogGroup'));

        echo $page->getId();
        if ( /*count($this->data['navPath'][0]) and */ count($childGroups)) {
            $firstPage = current($childGroups);
         //   echo count($this->data['navPath'][0]);
            return $this->redirect($this->convertUrl($firstPage->getUrl()));
        }
        
        $this->data['groups'] = array();
        if (count($childGroups)) {
            $this->data['groups'] = $childGroups;           
        } else {            
            $parentPage = end($this->data['navPath'][0]);
            if ($parentPage)                
                $this->data['groups'] = $this->getContentService()->getListPages($parentPage->getId(), new PageFilter('catalogGroup'));
        }


        $startPage = $this->getRequest()->get('page', 1);
        $idsChildGroup = array_keys($childGroups);


        //Третий уровень
        if (count($idsChildGroup)) {

            $subChildGroups = $this->getContentService()->getListPages($idsChildGroup, new PageFilter('catalogGroup'));
            $idsChildGroup = array_merge($idsChildGroup, array_keys($subChildGroups));
        }

        $idsGroup = array_merge(array($page->getId()), $idsChildGroup);
       
        try {
            $productsQuery = $this->getContentService()->getListPagesQuery($idsGroup, new PageFilter('product', 'p.price, p.title'));
            $this->data['products'] = $this->getPaginator()->paginate($productsQuery, $startPage, 15);
        } catch (\Exception $exc) {
            return $this->pageNotFound();
        }
        
        return $this->renderPage('PageType:catalog_group.html.twig');
    }

how to make links look like:
site.loc/catalogGroup-31177
site.loc/catalogGroup-31232/catalogGroup-31
site.loc/catalogGroup-3232/catalogGroup-5789/item
Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
keltanas, 2015-03-02
@keltanas

What a shame.
Why not just use Dynamic Router ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question