$qb = $this->createQueryBuilder('p'); return $qb ->addSelect('MONTHNAME(p.created) as month') ->addSelect('YEAR(p.created) as year') ->addSelect('COUNT(p) as cnt') ->groupBy('month, year') ->orderBy('p.created', 'DESC') ->getQuery() ->getArrayResult();
Expected known function, got 'MONTHNAME'
DoctrineExtensions\Query\Mysql\Month;
DoctrineExtensions\Query\Mysql\Year;
Acme\BlogBundle\Dql
and rejoice that there is such a wonderful repository. The function Monthname
done by the example of Month
. And according to the link , it remains for us to tell doctrine about these functions. # Doctrine Configuration doctrine: orm: dql: datetime_functions: month: Acme\BlogBundle\Dql\Month monthname: Acme\BlogBundle\Dql\Monthname year: Acme\BlogBundle\Dql\Year
namespace Acme\BlogBundle\Menu; use Knp\Menu\FactoryInterface; use Knp\Menu\MenuItem; use Symfony\Component\DependencyInjection\ContainerAware; class Builder extends ContainerAware { public function mainMenu (FactoryInterface $factory, array $options) { $menu = $factory->createItem('root'); $request = $this->container->get('request'); $menu ->addChild('Homepage', array( 'route' => 'homepage', )); $blog = $menu->addChild('Blog', array( 'route' => 'blog' )); $blog->addChild('BlogView',array( 'route' => 'blog_post_view', 'routeParameters' => array('id' => $request->get('id', 1)), 'display' => false )); return $menu; }
namespace Acme\BlogBundle\Menu; use Knp\Menu\FactoryInterface; use Knp\Menu\Iterator\CurrentItemFilterIterator; use Knp\Menu\Iterator\RecursiveItemIterator; use Knp\Menu\MenuItem; use Symfony\Component\DependencyInjection\ContainerAware; class Builder extends ContainerAware { public function mainMenu (FactoryInterface $factory, array $options) { $menu = $factory->createItem('root'); $request = $this->container->get('request'); $menu ->addChild('Homepage', array( 'route' => 'homepage', )); $blog = $menu->addChild('Blog', array( 'route' => 'blog' )); $blog->addChild('BlogView',array( 'route' => 'blog_view', 'routeParameters' => array('id' => $request->get('id', 1)), 'display' => false )); return $menu; } public function getCurrentItem (FactoryInterface $factory, array $options) { $menu = $this->mainMenu($factory, $options); $matcher = $this->container->get('knp_menu.matcher'); $voter = $this->container->get('knp_menu.voter.router'); $matcher->addVoter($voter); $treeIterator = new \RecursiveIteratorIterator( new RecursiveItemIterator( new \ArrayIterator(array($menu)) ), \RecursiveIteratorIterator::SELF_FIRST ); $iterator = new CurrentItemFilterIterator($treeIterator, $matcher); // Set Current as an empty Item in order to avoid exceptions on knp_menu_get $current = new MenuItem('', $factory); foreach ($iterator as $item) { $current = $item; break; } return $current; }
{% set breadcrumbs = knp_menu_get('AcmeBlogBundle:Builder:getCurrentItem').getBreadcrumbsArray() %} <ul class="breadcrumb"> <li> <i class="icon-home"></i> <a href="{{ path('homepage') }}">Home</a> <span class="icon-angle-right"></span> </li> {% for link in breadcrumbs %} {% if link.label != 'root' %} <li> <a href="{{ link.uri }}">{{ link.label|trans }}</a> {% if not loop.last %} <span class="icon-angle-right"></span> {% endif %} </li> {% endif %} {% endfor %} </ul>
getBreadCrumbsArray()
method, which will return what we need.Source: https://habr.com/ru/post/177257/
All Articles