是否存在類似於Zend Validator Identities的Zend過濾器?是否存在類似於Zend Validator Identical的Zend Filter?
我應該過濾輸入==「測試」
$el->addFilter('Identical','test');
的問題,這樣的過濾器不存在的情況。
感謝, 優素福
是否存在類似於Zend Validator Identities的Zend過濾器?是否存在類似於Zend Validator Identical的Zend Filter?
我應該過濾輸入==「測試」
$el->addFilter('Identical','test');
的問題,這樣的過濾器不存在的情況。
感謝, 優素福
我不知道這個過濾器應該如何工作,因爲它不清楚你的問題。無論如何,我做了一些自定義過濾器來檢查輸入字段的值是否等於某個$ token。如果它們等於輸入值,則會爲空字符串。
過濾器如下所示:
// file: APPLICATION_PATH/filters/Identical.php
class My_Filter_Identical implements Zend_Filter_Interface {
/**
* Token with witch input is compared
*
* @var string
*/
protected $_token;
/**
* Set token
*
* @param string
* @return void
*/
public function __construct($token = '') {
$this->_token = $token;
}
/**
* Filtering method
*
* @param string $value value of input filed
* @return string
*/
public function filter($value) {
if ($value !== $this->_token) {
return $value;
}
return '';
}
}
將它應用到一個給定的表單元素:
require_once (APPLICATION_PATH . '/filters/Identical.php');
$el1->addFilter(new My_Filter_Identical('test'));
關過程中,而不是require_once它可以被添加到您的資源自動加載的,但作爲一個例如,我認爲現在不需要。
編輯:
忘了提pregReplace過濾器。 同什麼自定義過濾器上面也可以使用pregReplace過濾器來完成:
$el1->addFilter('pregReplace',array('/test/',''));
但是,正如我所說,我不知道你怎麼想你的過濾工作。如果您提供更多信息,也許我可以提供更多幫助。
你的問題是不是所有的清楚 - 你想有一個過濾器,去除字test
?或者你是在談論過濾表單輸入?因此,考慮你的例子,你想從el
輸入中刪除什麼test
輸入包含?
如果你想從您的輸入刪除測試,你可以使用Zend_Filter_PregReplace
$filter = new Zend_Filter_PregReplace(array('match' => '/test/', 'replace' => ''));
$input = 'What is this test about!';
$filter->filter($input);
應該給你What is this about!
沒有如果已經進入到這會過濾相同的形式輸入的過濾器另一個我不認爲的投入。您可以嘗試創建自己的input filter並在輸入上執行自己的邏輯。
我不想使用PregReplace,我需要刪除所有輸入,所以它不好使用正則表達式。我知道我可以做我自己的過濾器,但我不知道如果我可以使用已存在於zend框架中的過濾器 – Yosef 2011-01-30 12:23:41
這是不是很清楚你想要做什麼。如果你給出更好的解釋。
我需要刪除所有輸入,所以它不好使用正則表達式。
如果你只是想清除表單元素中的數據,你可以使用下列之一:
清除設置的元素沒有什麼價值的元素值。
$ el-> setValue(null);
或重置所有表格元素
$形式 - >復位();
只有當輸入等於=='somevalue' – Yosef 2011-01-31 00:28:50
你能提供更多的信息,因爲它不清楚你的過濾如何工作,也許是一些例子。無論如何,你可以創建你自己的過濾器。 – Marcin 2011-01-28 03:18:33