我正在为我的表单设置一些过滤器和验证器,但是当我提交它时,会出现此错误:" Zend \ I18n \ Filter组件需要intl PHP扩展"。这是因为Alnum和Alpha验证器吗?
代码:
public function getInputFilter() {
if (!$this->inputFilter) {
$inputFilter = new InputFilter();
$inputFilter->add(array(
'name' => 'email',
'required' => true,
"filters" => array(
array('name' => 'StringTrim'),
array('name' => 'StripTags')),
'validators' => array(
array(
'name' => 'Regex',
'options' => array(
'pattern' => '/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/',
'messages' => array(
Regex::NOT_MATCH => 'Е-майл адреса е невалиден.',
),
),
'break_chain_on_failure' => true
),
array(
'name' => 'EmailAddress',
'options' => array(
'messages' => array(
EmailAddress::INVALID_FORMAT => "Е-майл адреса е невалиден.",
EmailAddress::INVALID => "",
EmailAddress::INVALID_LOCAL_PART => "",
EmailAddress::INVALID_HOSTNAME => "",
EmailAddress::INVALID_SEGMENT => "",
EmailAddress::DOT_ATOM => "",
EmailAddress::INVALID_MX_RECORD => "",
),
),
),
),
));
$inputFilter->add((array(
'name' => 'name',
'required' => true,
"filters" => array(
array('name' => 'StringTrim'),
array('name' => 'StripTags')),
'validators' => array(
array(
'name' => 'Alpha',
),
),
)));
$inputFilter->add((array(
'name' => 'password',
'required' => true,
"filters" => array(
array('name' => 'StringTrim'),
array('name' => 'StripTags')),
'validators' => array(
array(
'name' => 'Alnum',
),
array(
'name' => 'StringLength',
'options' => array(
'min' => 6,
'max' => 12,
'messages' => array(
StringLength::INVALID => "Паролата трябва да е от 6 до 12 символа",
),
),
),
),
)));
}
答案 0 :(得分:10)
通过转到php.ini并取消注释extension=php_intl.dll
答案 1 :(得分:4)
在Ubuntu 16.04上,使用php 5.6,尝试:
sudo apt-get install php5.6-intl
然后
sudo service apache2 restart
答案 2 :(得分:1)
在具有PHP 7.2的Ubuntu 18.04上,尝试:
sudo apt-get install php7.2-intl
sudo service apache2 restart
如果不起作用,请在以下位置启用extension = php_intl.dll:
vim /etc/php/7.2/apache2/php.ini
sudo service apache2 restart
答案 3 :(得分:0)
如果您在MAC OS X上使用XAMPP,请将extension=intl.so
添加到/Applications/XAMPP/xamppfiles/etc/php.ini
文件中,然后重新启动Apache。
如果仍然无法正常工作,则需要安装intl。
您可以按照https://stackoverflow.com/a/32404183/3303055