Hello,
I’m new to symfony, and currently trying to tame the 3.1.15. Not that easy. My code tries to use a controller as a service to reuse an very simple form on any page.
An error message popped up :
Catchable Fatal Error: Argument 1 passed to AppBundle\Controller\ContactsFormController::__construct() must be an instance of FormFactoryInterface, none given, called in /mnt/400Go/www/sy1/var/cache/dev/classes.php on line 2485 and defined" at /mnt/400Go/www/sy1/src/AppBundle/Controller/ContactsFormController.php line 25
I can’t see where lays the error in my code, which is really basic. My “contacts_form_controller” is listed as a service (debug:container). Any help appreciated.
Best regards,
MC
Here is my services.yml :
# app/config/services.yml
services:
contacts_form_controller:
class: AppBundle\Controller\ContactsFormController
arguments: ['@form.factory','@templating','@doctrine.orm.entity_manager']
Here is the beginning of the controller :
// src/AppBundle/Controller/ContactsFormController.php
namespace AppBundle\Controller;
/* */
use AppBundle\Entity\ContactSetClass;
use AppBundle\Form\Type\ContactsFormType;
/* */
use Doctrine\ORM\EntityManager;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
/* */
use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
/* */
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/* */
class ContactsFormController extends Controller
{
private $formFactory;
private $templating;
public function __construct(\FormFactoryInterface $formFactory,\EngineInterface $templating)
{
$this->formFactory=$formFactory;
$this->templating=$templating;
}
[...]
Here is the call to the controller in another controller :
$request=new Request;
$response = $this->forward('AppBundle:ContactsForm:ContactsForm', array('request' => $request,));