文章出處
文章列表
如果在Controller中出現script代碼類似
$hello_str='Hello God<script>alert(3);</script>';
那么我不希望在傳給view的時候出現彈框,那么就在view文件中使用
use yii\helpers\Html;
并且輸出時使用 Html::encode
<?=Html::encode($view_hello_str);?>
還有一種方法就是過濾調script代碼:
use yii\helpers\HtmlPurifier;
然后:
<?=HtmlPurifier::process($view_hello_str);?>
輸出時只有 Hello God
使用該方法的目的是為了防止用戶惡意傳入參數
文章列表
全站熱搜