本文整理汇总了PHP中kartik\select2\Select2::init方法的典型用法代码示例。如果您正苦于以下问题:PHP Select2::init方法的具体用法?PHP Select2::init怎么用?PHP Select2::init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kartik\select2\Select2
的用法示例。
在下文中一共展示了Select2::init方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
/**
*
*/
public function init()
{
if (empty($this->parentName)) {
throw new InvalidParamException('RelativeSelect2 $parentName must be set!');
}
if (empty($this->url)) {
throw new InvalidParamException('RelativeSelect2 $url must be set!');
}
if ($this->parentModel instanceof Model) {
$this->options['data']['select2-parent-name'] = Html::getInputName($this->parentModel, $this->parentName);
} else {
$this->options['data']['select2-parent-name'] = $this->hasModel() ? Html::getInputName($this->model, $this->parentName) : $this->parentName;
}
if (is_array($this->url)) {
$this->url = Url::to($this->url);
}
$this->options['data']['select2-url'] = $this->url;
if (!empty($this->model) && isset($this->model->{$this->attribute})) {
if (is_array($this->model->{$this->attribute})) {
$this->options['data']['select2-selected-items'] = implode(',', $this->model->{$this->attribute});
} else {
$this->options['data']['select2-selected-items'] = $this->model->{$this->attribute};
}
} else {
$this->options['data']['select2-selected-items'] = $this->value;
}
parent::init();
RelativeSelect2Asset::register($this->getView());
}
示例2: init
public function init()
{
$this->setDefaultOptions();
if ($this->getSelect2Type() == 'ajax') {
$this->setAjaxOptions();
}
parent::init();
}
示例3: init
public function init()
{
$allValuesTmp = $this->view->params[$this->name . "_all"];
foreach ($allValuesTmp as $v) {
$allValuesTmp2[$v] = $v;
}
$selectedValuesTmp = $this->view->params[$this->name];
if ($selectedValuesTmp) {
foreach ($selectedValuesTmp as $v) {
$selectedValuesTmp2[$v] = $v;
}
} else {
$selectedValuesTmp2 = null;
}
$this->data = $allValuesTmp2;
$this->value = $selectedValuesTmp2;
$this->options = ['multiple' => true, 'placeholder' => $this->initialText];
parent::init();
}