Yii2-助手類(formatter)

胡勇健發表於2024-03-30

Yii2-助手類(formatter)

示例

Yii2-助手類(formatter)
echo \Yii::$app->formatter->asDatetime(time(),'Y-M-d H:i:s');           //2023-05-12 12:32:32
echo \Yii::$app->formatter->asRelativeTime('1447565922');               //2小時前
echo \Yii::$app->formatter->asUrl('www.baidu.com');                     //<a href="http://www.baidu.com">www.baidu.com</a>
echo \Yii::$app->formatter->asImage('test.jpg',['alt'=>'tesddd']);      //<img src="test.jpg" alt="tesddd">
echo \Yii::$app->formatter->asPercent('0.2');                           //20%
echo \Yii::$app->formatter->asEmail('3003030093@qq.com');               //<a href="mailto:3003030093@qq.com">3003030093@qq.com</a>

相關文章