Php Silex自定义验证程序注册
我创建了一个要在Silex中使用的自定义验证器,但在尝试访问它时出现以下错误:Php Silex自定义验证程序注册,php,symfony,silex,custom-validators,Php,Symfony,Silex,Custom Validators,我创建了一个要在Silex中使用的自定义验证器,但在尝试访问它时出现以下错误: PHP Fatal error: Class 'Sisu\\Validator\\Constraints\\ImeiValidator' not found in var/www/sisuwhitelabel/vendor/silex/silex/src/Silex/ConstraintValidatorFactory.php on line 85 我的限制: Imei.php <?php namesp
PHP Fatal error: Class 'Sisu\\Validator\\Constraints\\ImeiValidator'
not found in var/www/sisuwhitelabel/vendor/silex/silex/src/Silex/ConstraintValidatorFactory.php
on line 85
我的限制:
Imei.php
<?php
namespace Sisu\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
class Imei extends Constraint
{
public $message = "Here message";
public function validateBy()
{
return get_class($this).'Validator';
}
}
我在应用程序中使用它,如下所示:
$form->add('productIdentifier', 'text', array(
'required' => false,
'constraints' => array(
new Imei(
array('message' => 'xxxxx')
)
)
);
我找到了答案。
约束Imei和验证器ImeiValidator应位于同一文件夹中
有关此主题的更多信息,请参见:
<?php
namespace Sisu\Provider;
use Silex\Application;
use Silex\ServiceProviderInterface;
use Sisu\Validator\ImeiValidator;
class ImeiValidatorServiceProvider implements ServiceProviderInterface
{
public function register(Application $app)
{
$app['validator.imei'] = $app->share(function($app) {
$validator = new ImeiValidator();
return $validator;
});
}
public function boot(Application $app)
{
}
}
$app->register(new Sisu\Provider\ImeiValidatorServiceProvider());
$form->add('productIdentifier', 'text', array(
'required' => false,
'constraints' => array(
new Imei(
array('message' => 'xxxxx')
)
)
);