1 | <?php |
||
24 | class FileInput extends InputWidget |
||
25 | { |
||
26 | /** |
||
27 | * To render the template as a file input. |
||
28 | */ |
||
29 | const STYLE_INPUT = 10; |
||
30 | /** |
||
31 | * To render the template as a button. |
||
32 | */ |
||
33 | const STYLE_BUTTON = 20; |
||
34 | /** |
||
35 | * To render the template with thumbnail. |
||
36 | */ |
||
37 | const STYLE_IMAGE = 30; |
||
38 | /** |
||
39 | * To render custom templates. If used, [[$customView]] must be initialized. |
||
40 | */ |
||
41 | const STYLE_CUSTOM = 40; |
||
42 | /** |
||
43 | * @var int the type of Jasny File Input style to render. |
||
44 | * Please, see [Jasny Bootstrap File Input](http://jasny.github.io/bootstrap/javascript/#fileinput) to see the |
||
45 | * different displays. |
||
46 | */ |
||
47 | public $style; |
||
48 | /** |
||
49 | * @var string the custom view to render the field. This view will receive the following variables: |
||
50 | * - $field: The actual file input field |
||
51 | * - $thumbnail: If set the thumbnail to display previous selected image |
||
52 | */ |
||
53 | public $customView; |
||
54 | |||
55 | /** |
||
56 | * @var array additional parameters passed to $customView |
||
57 | */ |
||
58 | public $customParams = []; |
||
59 | /** |
||
60 | * @var string the thumbnail to be displayed if [[STYLE_CUSTOM]] or [[STYLE_IMAGE]] has been selected. Thumbnail |
||
61 | * is used to display an image that was previously loaded. |
||
62 | */ |
||
63 | public $thumbnail; |
||
64 | /** |
||
65 | * @var array the event handlers for the underlying Jasny file input JS plugin. |
||
66 | * Please refer to the [Jasny Bootstrap File Input](http://jasny.github.io/bootstrap/javascript/#fileinput) plugin |
||
67 | * Web page for possible events. |
||
68 | */ |
||
69 | 9 | public $clientEvents = []; |
|
70 | |||
71 | 9 | /** |
|
72 | 3 | * Initializes the widget. |
|
73 | 3 | */ |
|
74 | public function init() |
||
96 | 3 | ||
97 | 3 | /** |
|
98 | 3 | * {@inheritdoc} |
|
99 | */ |
||
100 | public function run() |
||
110 | |||
111 | 3 | /** |
|
112 | 3 | * Renders the template according. |
|
113 | 3 | * |
|
114 | 3 | * @param $field |
|
115 | 3 | * |
|
116 | 3 | * @throws \yii\base\InvalidConfigException |
|
117 | 3 | * |
|
118 | 3 | * @return string |
|
119 | 3 | */ |
|
120 | 3 | public function renderTemplate($field) |
|
143 | 3 | ||
144 | 3 | /** |
|
145 | 3 | * Registers Jasny File Input Bootstrap plugin and the related events. |
|
146 | 3 | */ |
|
147 | 3 | public function registerClientScript() |
|
163 | } |
||
164 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: