I am new to Symfony. I try to make a service from one of my classes.
When I run bin/console cache:clear I get this error:
In ResolveNamedArgumentsPass.php line 66:
Invalid service "my.myform.service": did you forget to add the "$" prefix to argument "container"?
Here is my code:
config/services.yaml:
my.myform.service:
class: AppControllerMyformController
arguments:
container: "@service_container"
src/Controller/MessageController.php:
namespace AppController;
use AppEntityProduct;
use DoctrineORMEntityManagerInterface;
use AppControllerMyformController;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentRoutingAnnotationRoute;
use SymfonyBundleFrameworkBundleControllerAbstractController;
class MessageController extends AbstractController
{
/**
* @Route("/message", name="message", methods="GET")
*/
public function index(Request $request): Response
{
//$myform = new MyformController();
//$myform->createMyform();
$this->get("my.myform.service")->createMyform();
...
src/Controller/MyformController.php:
namespace AppController;
use AppEntityMyform;
use DoctrineORMEntityManagerInterface;
use SymfonyBundleFrameworkBundleControllerAbstractController;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentRoutingAnnotationRoute;
class MyformController extends AbstractController
{
public function __construct($container )
{
$this->container = $container;
}
/* protected function get($service)
{
return $this->container->get($service);
}
*/
public function createMyform(): Response
{
// you can fetch the EntityManager via $this->getDoctrine()
What's wrong?
PS I commented function get() in MyformController because I had an error:
PHP Fatal error: Declaration of AppControllerMyformController::get($service) must be compatible with SymfonyBundleFrameworkBundleControllerAbstractController::get(string $id): object in /home/admin/web/alpin52.ru/public_html/miriada/myform/src/Controller/MyformController.php on line 51
Thanks.
question from:
https://stackoverflow.com/questions/65830935/symfony-4-invalid-service-my-myform-service 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…