Как получить доступ к репозиторию в сущности?
вроде это работает только с SF2 Неужели бросать 3 версию?
Неужели бросать 3 версию?
namespace Site\AppBundle\Twig;
use Symfony\Component\HttpFoundation\Request;
class TwigExtension extends \Twig_Extension
{
public function getTests()
{
return array(
new \Twig_SimpleTest('match_route', array($this, 'matchRoute')),
);
}
public function matchRoute(Request $request, $routeName, $routeParameters = array())
{
if (!$requestRouteName = $request->attributes->get('_route')) {
return false;
}
if ($requestRouteName != $routeName) {
return false;
}
if (empty($routeParameters)) {
return true;
}
if (!$requestRouteParameters = $request->attributes->get('_route_params')) {
return false;
}
$arrayIntersect = array_intersect_assoc($requestRouteParameters, $routeParameters);
if (count($arrayIntersect) == count($routeParameters)) {
return true;
}
return false;
}
public function getName()
{
return 'twig_extension';
}
}
{% if app.request is match_route('homepage') %}текущая страница "homepage"{% endif %}
{% if app.request is match_route('entry', { 'name': 'info' }) %}текущая страница "info"{% endif %}
{% if app.request.attributes.get('_route') == 'homepage' %}
<li class="selected"><span>HOME</span></li>
{% else %}
<li><a href="{{ path('homepage') }}">HOME</a></li>
{% endif %}
{% if app.request.attributes.get('_route') == 'entry' and
app.request.attributes.get('_route_params').name is defined and
app.request.attributes.get('_route_params').name == 'info' %}
<li class="selected"><span>INFO</span></li>
{% else %}
<li><a href="{{ path('entry', { 'name': 'info' }) }}">INFO</a></li>
{% endif %}
{% if app.request.attributes.get('_route') == 'entry' and
app.request.attributes.get('_route_params').name is defined and
app.request.attributes.get('_route_params').name == 'settings' %}
<li class="selected"><span>SETTINGS</span></li>
{% else %}
<li><a href="{{ path('entry', { 'name': 'settings' }) }}">SETTINGS</a></li>
{% endif %}
{% if app.request.attributes.get('_route') == 'download' %}
<li class="selected"><span>DOWNLOAD</span></li>
{% else %}
<li><a href="{{ path('download') }}">DOWNLOAD</a></li>
{% endif %}