webandcow/cakephp-sanitize

行为 Sanitize

安装: 24

依赖: 0

建议者: 0

安全: 0

星星: 0

关注者: 2

分支: 0

开放问题: 0

类型:cakephp-plugin

0.0.4 2021-03-31 14:39 UTC

This package is auto-updated.

Last update: 2024-09-29 06:08:37 UTC


README

允许清理输入数据的 CakePHP 插件。

使用行为

您可以通过 $actAs 变量将行为附加到您的模型上。

class User extends AppModel {

    public $actsAs = [
		'Sanitize' => [
			'fields' => [
				'nom' => 'stripHtml', 
				'prenom' => 'stripHtml', 
				'username' => 'stripHtml', 
			]
        ]
    ];

}

以下示例显示了如何使用 stripHtml 方法来清理 nomprenomusername 字段。

现在让我们看看如何将行为附加到您的模型上的另一种方法。

class User extends AppModel {

    public $actsAs = [
		'Sanitize' => [
			'fields' => '*',
			'exclude' => ['password', 'age'], 
			'map' => [
				'string' => 'stripHtml',
				'text' => 'stripHtml'
			]
        ]
    ];

}

对于 fields 键的 * 值,允许清理模型中的所有字段。您可以通过 exclude 键轻松排除某些字段从清理过程。在我们的示例中,passwordage 字段将不会被清理。您可以为不同类型的字段定义使用的方法。在上面的示例中,stringtext 类型的字段将使用 stripHtml 方法来清理内容。

当前可用方法

以下是当前行为的方法列表

  • stripHtml 用于从字段内容中删除所有 HTML 标签
  • stripScript 用于从字段内容中删除 <img><script><style><link> 标签

待定

  • 单元测试
  • 集成新方法