Symfony2新手在这里
我尝试在我的应用程序中创建一个服务。我遵循symfony文档 下面是我的代码:文件BC/MBundle/资源/config/services.yml:
---
services:
metas:
class: BC'MBundle'Metas'Metas
文件BC/MBundle/搜索
<?php
namespace BC'MBundle'Metas;
class Metas {
public function queryAllCategories() {
return array();
}
}
文件BC/MBundle/控制器/AController.php
<?php
namespace BC'MBundle'Controller;
// ...
use BC'MBundle'Metas'MetasController;
class AController extends Controller {
public function homeAction() {
return $this->render(
'tpl.html.twig',
array(
'categories' => $this->get('metas')->queryAllCategories(),
)
);
}
}
错误是:
Attempted to load class "Metas" from namespace "BC'MBundle'Metas".
Did you forget a "use" statement for another namespace?
-
移动
文件BC/MBundle/搜索
BC/MBundle/搜索/Metas.php
-
尝试使用
清除缓存php app/console cache:clear
或
php app/console cache:clear --env=prod