gozoro/yii2-helpers

Yii2 框架的辅助工具。扩展了标准辅助工具。

安装: 4

依赖者: 2

建议者: 0

安全性: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

类型:yii2-extension

v1.0.0 2024-04-03 14:41 UTC

This package is auto-updated.

Last update: 2024-09-03 16:00:24 UTC


README

作为静态函数的 Yii2 框架辅助工具。

HTML 辅助工具

Html::rus2translit("привет мир"); // privet mir

Html::str2url("привет мир!") // privet-mir

Html::text("это ссылка http://example.com") // это ссылка <a href="http://example.com">http://example.com</a>

Html::csrfHiddenInput(); //  Return string with CSRF hidden input

Html::video("./example.mp4") // Returns string with video tag or youtube-iframe.

JSON 辅助工具

$options = [
	'valueString' => 'string',
	'valueInt'    => 5,
	'valueFloat'  => 4.3,
	'valueNull'   => null,
	'valueBool'   => true,
	'valArray'    => ['a', 'b', 'c'],
	'valAssoc'    => ['a'=>'apple', 'b'=>2, 'c'=>1],
	'func'        => 'function(val){return val;}',
];

Json::optionsEncode($options);

返回带有 JavaScript 代码的字符串

 
 {
 	"valueString": "string",
 	"valueInt": 5,
 	"valueFloat": 4.3,
 	"valueNull": null,
 	"valueBool": true,
 	"valArray": ["a", "b", "c"],
 	"valAssoc": {"a":"apple", "b":2, "c":1},
 	"func": function(val){return val;},
 }

URL 辅助工具

现在您可以解析和编辑 URL

$url = new Url("https://example.com/my-path");
echo $url->getScheme(); // https
echo $url->getHost(); // example.com
echo $url->getPath(); // /my-path
// etc