本文整理匯總了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();
}