我想在 zend 框架 2 中使用 SeparatorToSeparator() 过滤器来过滤我的数据。
如何将两个参数(setSearchSeparator 和 setReplacementSeparator)传递给构造函数?
$inputFilter->add(array(
'name' => 'supplierName',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
array('name'=>"Word\SeparatorToSeparator"
),
));
路径:zendframework/bin/libary/Zend/Filter/Word/SeparatorToSeparator.php
class SeparatorToSeparator extends AbstractFilter
{
protected $searchSeparator = null;
protected $replacementSeparator = null;
/**
* Constructor
*
* @param string $searchSeparator Separator to search for
* @param string $replacementSeparator Separator to replace with
*/
public function __construct($searchSeparator = ' ', $replacementSeparator = '-')
{
$this->setSearchSeparator($searchSeparator);
$this->setReplacementSeparator($replacementSeparator);
}
更新
$inputFilter->add(array(
'name' => 'supplierName',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
array('name'=>'Word\SeparatorToSeparator',
'options' => array(
'search_separator' => 'a',
'replacement_separator' => 'b'
)
)
),
));
我收到此错误消息:
警告:preg_quote() 期望参数 1 是字符串,数组在 C:\wamp\www\tebipdevelopment\vendor\zendframework\zendframework\library\Zend\Filter\Word\SeparatorToSeparator.php 中的第 92 行
我已经打开了这一行,并打印了这样的错误消息。
print_r($this->searchSeparator);
print_r($this->replacementSeparator);
结果
数组( [search_separator] => a [replacement_separator] => b )
在这种情况下,search_separator 等于数组而不是字符串