How to create a new helper in Yii2 framework: Create a new file “Utils.php” in “app-basic\helpers” or in other folder, location is up to you, but keep things organized!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<?php namespace yii\helpers; use Yii; class Utils { public static function pre($mixed_data) { print '<pre style="white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -o-pre-wrap; background: #faf8f0; border: 1px solid silver; padding: 2px; font-weight: normal; font-family: Monospace, Courier">'; print_r($mixed_data); <span style="line-height: 1.1em;">print '</pre>'; </span><span style="line-height: 1.1em;">} </span><span style="line-height: 1.1em;">public static function code($mixed_data) </span><span style="line-height: 1.1em;">{ <span style="line-height: 1.1em;"> print '<code style=" display: block; padding: 0.5em 1em; border: 1px solid #bebab0;">'; </span></span><span style="line-height: 1.1em;">print_r($mixed_data); </span><span style="line-height: 1.1em;">print '</code>'; </span><span style="line-height: 1.1em;">} </span>} |
In this helper we have 2 functions to display raw