webandcow / cakephp-sanitize
行为 Sanitize
0.0.4
2021-03-31 14:39 UTC
Requires
- php: >=5.6
README
允许清理输入数据的 CakePHP 插件。
使用行为
您可以通过 $actAs 变量将行为附加到您的模型上。
class User extends AppModel { public $actsAs = [ 'Sanitize' => [ 'fields' => [ 'nom' => 'stripHtml', 'prenom' => 'stripHtml', 'username' => 'stripHtml', ] ] ]; }
以下示例显示了如何使用 stripHtml
方法来清理 nom
、prenom
、username
字段。
现在让我们看看如何将行为附加到您的模型上的另一种方法。
class User extends AppModel { public $actsAs = [ 'Sanitize' => [ 'fields' => '*', 'exclude' => ['password', 'age'], 'map' => [ 'string' => 'stripHtml', 'text' => 'stripHtml' ] ] ]; }
对于 fields
键的 *
值,允许清理模型中的所有字段。您可以通过 exclude
键轻松排除某些字段从清理过程。在我们的示例中,password
和 age
字段将不会被清理。您可以为不同类型的字段定义使用的方法。在上面的示例中,string
和 text
类型的字段将使用 stripHtml
方法来清理内容。
当前可用方法
以下是当前行为的方法列表
stripHtml
用于从字段内容中删除所有 HTML 标签stripScript
用于从字段内容中删除<img>
、<script>
、<style>
、<link>
标签
待定
- 单元测试
- 集成新方法