1 | <?php |
||
22 | class FileUploadUI extends BaseUpload |
||
23 | { |
||
24 | /** |
||
25 | * @var bool whether to use the Bootstrap Gallery on the images or not |
||
26 | */ |
||
27 | public $gallery = true; |
||
28 | /** |
||
29 | * @var bool load previously uploaded images or not |
||
30 | */ |
||
31 | public $load = false; |
||
32 | /** |
||
33 | * @var array the HTML attributes for the file input tag. |
||
34 | * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. |
||
35 | */ |
||
36 | public $fieldOptions = []; |
||
37 | /** |
||
38 | * @var string the ID of the upload template, given as parameter to the tmpl() method to set the uploadTemplate option. |
||
39 | */ |
||
40 | public $uploadTemplateId; |
||
41 | /** |
||
42 | * @var string the ID of the download template, given as parameter to the tmpl() method to set the downloadTemplate option. |
||
43 | */ |
||
44 | public $downloadTemplateId; |
||
45 | /** |
||
46 | * @var string the form view path to render the JQuery File Upload UI |
||
47 | */ |
||
48 | public $formView = 'form'; |
||
49 | /** |
||
50 | * @var string the upload view path to render the js upload template |
||
51 | */ |
||
52 | public $uploadTemplateView = 'upload'; |
||
53 | /** |
||
54 | * @var string the download view path to render the js download template |
||
55 | */ |
||
56 | public $downloadTemplateView = 'download'; |
||
57 | /** |
||
58 | * @var string the gallery |
||
59 | */ |
||
60 | public $galleryTemplateView = 'gallery'; |
||
61 | |||
62 | |||
63 | /** |
||
64 | * @inheritdoc |
||
65 | */ |
||
66 | 2 | public function init() |
|
77 | |||
78 | /** |
||
79 | * @inheritdoc |
||
80 | */ |
||
81 | 1 | public function run() |
|
93 | |||
94 | /** |
||
95 | * Registers required script for the plugin to work as jQuery File Uploader UI |
||
96 | */ |
||
97 | 1 | public function registerClientScript() |
|
133 | } |
||
134 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.