아래와 같이 컨트롤러에서 유효성 검사를 추가하려고했습니다. 하지만 항상 이것을 보여줍니다.젠드 프레임 워크 2의 컨트롤러에서 폼 유효성 검사를 추가하는 방법
if ($request->getPost('ownerType') == "Company") {
$form->getInputFilter()->get('companyName')->getValidatorChain()->addValidator('required');
}
오류를 보여줍니다. 나는 아래의 오류와 혼동했다.
Catchable fatal error: Argument 1 passed to Zend\Validator\ValidatorChain::addValidator() must implement interface Zend\Validator\ValidatorInterface, string given, called in E:\xampp\htdocs\hossbrag\module\WebApp\src\WebApp\Controller\JobController.php on line 177 and defined in E:\xampp\htdocs\hossbrag\vendor\zendframework\zendframework\library\Zend\Validator\ValidatorChain.php on line 100
내 컨트롤러는 적절한 솔루션을 얻기 위해 내 컨트롤러에서 변경해야 여기에서
<?php
namespace WebApp\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use WebApp\Entity\User;
use Zend\View\Model\JsonModel;
use vendor\mpdf\mpdf;
class JobController extends AuthenticatedController
{
public function createAction()
{
$form = new \WebApp\Form\JobpostingForm();
$form->get('companyName')->setValueOptions($company);
$checkAgreement = true;
$request = $this->getRequest();
if ($request->getPost('ownerType') == "Company") {
$form->getInputFilter()->get('companyName')->getValidatorChain()->addValidator('required');
}
}
}
입니다.) Zend\Validator\ValidatorInterface
될 것이라고 확인
먼저 하나를, 당신은 명확한 오류가 발생하면
여기에서 해결책을 찾을 수 있습니다 .. http://stackoverflow.com/questions/15782107/zend-framework-2-removed-form-element-causes -validation-to-fail. 이 줄은 내 솔루션 $ form-> setValidationGroup ('name', 'email', 'subject', 'message')입니다. 엔티티에 모든 유효성 검사를 넣고 유효성을 검사 한 코드 중 위의 코드 만 언급하면됩니다. –