14
14
* public function actions()
15
15
* {
16
16
* return [
17
- * 'link-preview' => LinkPreviewAction ::className()
17
+ * 'link-preview' => \yii2mod\linkpreview\actions\LinkPreview ::className()
18
18
* ];
19
19
* }
20
+ *
20
21
* 2. Add widget to your page as follows:
21
- * echo \app\components\preview \LinkPreview::widget([
22
+ * echo \yii2mod\linkpreview \LinkPreview::widget([
22
23
* 'selector' => '#your-input-id or .someclass',
23
24
* 'clientOptions' => [
24
25
* 'previewActionUrl' => \yii\helpers\Url::to(['link-preview'])
@@ -55,16 +56,17 @@ class LinkPreview extends Widget
55
56
*/
56
57
public function init ()
57
58
{
59
+ parent ::init ();
60
+
58
61
if (empty ($ this ->id )) {
59
62
throw new InvalidConfigException ("The 'id' property is required. " );
60
63
}
64
+
61
65
if (empty ($ this ->pjaxContainerId )) {
62
66
throw new InvalidConfigException ("The 'pjaxContainerId' property is required. " );
63
67
}
64
- echo $ this ->render ($ this ->view , [
65
- 'pjaxContainerId ' => $ this ->pjaxContainerId ,
66
- ]);
67
- parent ::init ();
68
+
69
+ $ this ->registerAssets ();
68
70
}
69
71
70
72
/**
@@ -73,12 +75,21 @@ public function init()
73
75
* @return string the result of widget execution to be outputted
74
76
*/
75
77
public function run ()
78
+ {
79
+ return $ this ->render ($ this ->view , [
80
+ 'pjaxContainerId ' => $ this ->pjaxContainerId ,
81
+ ]);
82
+ }
83
+
84
+ /**
85
+ * Register assets
86
+ */
87
+ protected function registerAssets ()
76
88
{
77
89
$ view = $ this ->getView ();
78
90
LinkPreviewAsset::register ($ view );
79
91
$ options = $ this ->getClientOptions ();
80
92
$ view ->registerJs ("$(' {$ this ->selector }').linkPreview( {$ options }); " , $ view ::POS_END );
81
- parent ::run ();
82
93
}
83
94
84
95
/**
0 commit comments