1
|
|
|
<?php
|
2
|
|
|
/**
|
3
|
|
|
* @author Alexey Tatarinov <[email protected]>
|
4
|
|
|
* @link https://github.com/shogodev/argilla/
|
5
|
|
|
* @copyright Copyright © 2003-2015 Shogo
|
6
|
|
|
* @license http://argilla.ru/LICENSE
|
7
|
|
|
*/
|
8
|
|
|
class OnFlyWidget extends CWidget
|
9
|
|
|
{
|
10
|
|
|
const TYPE_INPUT = 'input';
|
11
|
|
|
|
12
|
|
|
const TYPE_DROPDOWN = 'dropDown';
|
13
|
|
|
|
14
|
|
|
/**
|
15
|
|
|
* URL для AJAX запроса.
|
16
|
|
|
*
|
17
|
|
|
* @var string
|
18
|
|
|
*/
|
19
|
|
|
public $ajaxUrl;
|
20
|
|
|
|
21
|
|
|
/**
|
22
|
|
|
* @var string $type тип (OnFlyWidget::TYPE_INPUT, OnFlyWidget::TYPE_DROPDOWN)
|
23
|
|
|
*/
|
24
|
|
|
public $type;
|
25
|
|
|
|
26
|
|
|
public $items = array();
|
27
|
|
|
|
28
|
|
|
public $attribute;
|
29
|
|
|
|
30
|
|
|
public $primaryKey;
|
31
|
|
|
|
32
|
|
|
public $value;
|
33
|
|
|
|
34
|
|
|
public $htmlOptions = array();
|
35
|
|
|
|
36
|
|
|
public function init()
|
37
|
|
|
{
|
38
|
|
|
if( !isset($this->ajaxUrl, $this->attribute, $this->primaryKey) )
|
39
|
|
|
throw new RequiredPropertiesException(__CLASS__, array('ajaxUrl', 'attribute', 'primaryKey', 'type'));
|
40
|
|
|
|
41
|
|
|
self::registerOnFlyScripts();
|
42
|
|
|
}
|
43
|
|
|
|
44
|
|
|
public function run()
|
45
|
|
|
{
|
46
|
|
|
$htmlOptions = CMap::mergeArray($this->htmlOptions, array(
|
47
|
|
|
'data-onflyedit' => implode('-', array($this->attribute, $this->primaryKey)),
|
48
|
|
|
'data-ajax-url' => $this->ajaxUrl,
|
49
|
|
|
));
|
50
|
|
|
|
51
|
|
|
switch($this->type)
|
52
|
|
|
{
|
53
|
|
|
case self::TYPE_INPUT;
|
54
|
|
|
$htmlOptions['class'] = 'onfly-edit';
|
55
|
|
|
$html = CHtml::tag('span', $htmlOptions, $this->value);
|
56
|
|
|
break;
|
57
|
|
|
|
58
|
|
|
case self::TYPE_DROPDOWN;
|
59
|
|
|
$htmlOptions['class'] = 'onfly-edit-dropdown';
|
60
|
|
|
$htmlOptions['style'] = 'margin-bottom: 0px; width: auto;';
|
61
|
|
|
|
62
|
|
|
$html = CHtml::dropDownList('', $this->value, $this->items, $htmlOptions);
|
63
|
|
|
break;
|
64
|
|
|
}
|
65
|
|
|
|
66
|
|
|
echo $html;
|
|
|
|
|
67
|
|
|
}
|
68
|
|
|
|
69
|
1 |
|
public static function registerOnFlyScripts()
|
70
|
|
|
{
|
71
|
1 |
|
$scriptUrl = Yii::app()->assetManager->publish(dirname(__FILE__).'/js');
|
72
|
1 |
|
Yii::app()->clientScript->registerScriptFile($scriptUrl.'/jquery.onFlyEdit.js', CClientScript::POS_END);
|
73
|
1 |
|
Yii::app()->clientScript->registerScriptFile($scriptUrl.'/onFlyModule.js', CClientScript::POS_END);
|
74
|
|
|
}
|
75
|
|
|
} |
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: