Multilang.php
1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace common\widgets;
use common\models\Language;
use yii\base\InvalidParamException;
use yii\base\Widget;
use yii\bootstrap\ActiveForm;
class Multilang extends Widget
{
public $id;
public $langs;
public $data_langs = [];
public $ajaxpath;
public $form;
public function init()
{
parent::init();
if(empty($this->id)) {
$this->id = \Yii::$app->security->generateRandomString(8);
}
if(empty($this->langs)) {
$this->langs = Language::getActiveLanguages();
}
if(empty($this->ajaxpath)) {
throw new InvalidParamException('ajaxpath must be set');
}
if(empty($this->form)) {
throw new InvalidParamException('form must be set');
}
ob_start();
echo $this->render('multilang-begin', ['id' => $this->id, 'langs' => $this->langs, 'data_langs' => $this->data_langs, 'ajaxpath' => $this->ajaxpath, 'form' => $this->form]);
}
public function run()
{
echo $this->render('multilang-end', ['id' => $this->id, 'langs' => $this->langs, 'data_langs' => $this->data_langs, 'ajaxpath' => $this->ajaxpath, 'form' => $this->form]);
$content = ob_get_clean();
return $content;
}
}