Symfony 2.5 "You requested a nonexistent service" siteTest.b "
There is no problem starting the workspace / app _dev.php. But when I try to run workspace / app.php I get:
"You requested a nonexistent service" siteTest.b "
I don't have the first clue what I am 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
CSI / 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;
}
}
Cci / 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();
}
}
+3
source to share
2 answers
you may also need to add below code inside
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: '@TestBundle/Resources/config/services.yml' }
Alternatively you can use the cookbook config http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class
+12
source to share