Symfony 2.5 "You have requested a non-existent service "siteTest.b"
18,922
Solution 1
run command php app/console cache:clear --env=prod
to clear your prod
cache
Solution 2
you might also need to add the code below inside
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: '@TestBundle/Resources/config/services.yml' }
alternatively you can use the cookbook configurations http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class
Author by
Admin
Updated on June 04, 2022Comments
-
Admin almost 2 years
When run workspace/app_dev.php, no problem. But when I try to run workspace/app.php I get:
"You have requested a non-existent service "siteTest.b"
I dont have the first clue what am I doing wrong.
app/config/config.yml :
imports: - { resource: parameters.yml } - { resource: security.yml } framework: secret: "%secret%" router: resource: "%kernel.root_dir%/config/routing.yml" strict_requirements: ~ form: ~ csrf_protection: ~ validation: { enable_annotations: true } templating: engines: ['twig'] default_locale: "%locale%" trusted_hosts: ~ trusted_proxies: ~ session: handler_id: ~ fragments: ~ http_method_override: true
src/Site/TestBundle/Resources/config/services.yml:
parameters: siteTest.aa: Site\TestBundle\Controller\a services: siteTest.b: class: %siteTest.aa%
src/Site/TestBundle/DependencyInjection/SiteTestExtension.php :
namespace Site\TestBundle\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\DependencyInjection\Loader; class SiteTestExtension extends Extension { /** * {@inheritDoc} */ public function load(array $configs, ContainerBuilder $container) { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yml'); } }
src/Site/TestBundle/Controller/a.php :
namespace Site\TestBundle\Controller; class a { public function printTest() { var_dump('Test'); exit; } }
src/Site/TestBundle/Controller/DefaultController.php:
namespace Site\TestBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Component\HttpFoundation\Response; class DefaultController extends Controller { public function indexAction() { $aaa = $this->get('siteTest.b'); exit(); } }