Я переношу свой проект Symfony с 3.3 на 4, код за кодом (копирование и вставка).
Я получил ошибку в моем расширении ветки вся ошибка.
это мой config.yaml:
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: 'en'
brochures_directory: '%kernel.project_dir%/public/uploads/brochures'
services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
public: false # Allows optimizing the container by removing unused services; this also means
# fetching services directly from the container via $container->get() won't work.
# The best practice is to be explicit about your dependencies anyway.
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '../src/*'
exclude: '../src/{Entity,Migrations,Tests,Kernel.php}'
# controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']
App\Twig\:
resource: '../src/Twig'
arguments:
$doctrine : '@doctrine'
$tokenStorage : '@security.token_storage'
tags:
- { name: twig.extension }
autowire: true
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
App\Service\FileUploader:
arguments:
$targetDirectory: '%brochures_directory%'
Как видите, я загружаю все расширения веток файлов здесь:
App\Twig\:
resource: '../src/Twig'
arguments:
$doctrine : '@doctrine'
$tokenStorage : '@security.token_storage'
tags:
- { name: twig.extension }
autowire: true
это работает в 3.3, но не работает в 4. О, это пример моего расширения ветки:
<?php
namespace App\Twig;
use Symfony\Bridge\Doctrine\RegistryInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
class TwigExtension extends \Twig_Extension
{
protected $doctrine;
protected $user;
public function __construct(RegistryInterface $doctrine, TokenStorageInterface $tokenStorage)
{
$this->doctrine = $doctrine;
if($tokenStorage->getToken() != null) {
$this->user= $tokenStorage->getToken()->getUser();
}
}
public function getFunctions() {
return array(
new TwigFilter('price', array($this, 'priceFilter'))
);
}
public function priceFilter($number, $decimals = 0, $decPoint = '.', $thousandsSep = ',')
{
$price = number_format($number, $decimals, $decPoint, $thousandsSep);
$price = '$'.$price;
return $price;
}
}
и я попытался вызвать этот фильтр:
<h1>{{ countProducts | price }}</h1>
это ОШИБКА:
Uncaught PHP Exception Twig_Error_Syntax: "Unknown "price" filter."
как решить эту проблему?
потому что это работает в проектах Symfony 3.3