當運行工作區/ app_dev.php,沒有問題,但,當我嘗試運行工作區/ app.php我得到:Symfony的2.5「您已請求不存在的服務‘siteTest.b’
「你已經要求一個不存在的服務」siteTest.b「
我沒有第一個線索我做錯了什麼。
應用程序/配置/ 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 /網站/ TestBundle /資源/配置/ services.yml:
parameters:
siteTest.aa: Site\TestBundle\Controller\a
services:
siteTest.b:
class: %siteTest.aa%
的src /網站/ 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 /站點/ TestBundle /控制器/ a.php只會:
namespace Site\TestBundle\Controller;
class a {
public function printTest() {
var_dump('Test');
exit;
}
}
SRC /站點/ TestBundle /控制器/ 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();
}
}
清楚你的'prod'緩存 – dmnptr 2014-09-18 18:07:48