未找到控制器类

时间:2017-10-17 16:52:03

标签: php symfony

我的symfony 2项目中最奇怪的事情,就像我通常那样添加一个新的控制器,设置路由,由于某种原因它不会起作用......

src / AppBundle / Controller / SupplierController.php:

namespace AppBundle\Controller;
// omitted all necessary use statements, but they are normally here... 

class SupplierController extends Controller
{
    public function signUpAction(Request $request)
    {
        $defaultData = array('message' => 'Type your message here');
        $form = $this->createFormBuilder($defaultData)
            ->add('fname', TextType::class, array('label' => 'First Name'))
            ->add('lname', TextType::class, array('label' => 'Last Name'))
            ->add('company', TextType::class)
            ->add('email', EmailType::class)
            ->add('phone', NumberType::class, array('label' => 'Tel. No.'))
            ->add('message', TextareaType::class)
            ->add('receiveUpdates', CheckboxType::class)
            ->add('send', SubmitType::class)
            ->getForm();

        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            // data is an array with "name", "email", and "message" keys
            $data = $form->getData();
        }

        return $this->render('AppBundle:Suppliers:SignUp:_form.html.twig', array('form' => $form->createView()));
    }

}

app / config / routing.yml:

// other routes omitted... 

supplier_sign_up:
    path: /supplier/register
    methods: [GET]
    defaults:
        _controller: AppBundle:Supplier:signUp

运行页面:

The _controller value "AppBundle:Supplier:signUp" maps to a
"AppBundle\Controller\SupplierController" class, but this class was not
found. Create this class or check the spelling of the class and its
namespace.

很奇怪吗?路线识别控制器,命名空间是正确的,检查拼写等。无法解决...任何帮助将不胜感激。干杯

1 个答案:

答案 0 :(得分:0)

所以这被证明是一个Sylius问题,主要是由于Sylius使用symfony的方式我必须将我的表单配置为sylius资源并通过服务调用它