本文整理汇总了PHP中yii\helpers\ArrayHelper::remove方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayHelper::remove方法的具体用法?PHP ArrayHelper::remove怎么用?PHP ArrayHelper::remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\ArrayHelper
的用法示例。
在下文中一共展示了ArrayHelper::remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* @inheritDoc
*/
public function render($content = null)
{
if ($content === null) {
if (!isset($this->parts['{beginWrapper'])) {
$options = $this->wrapperOptions;
$tag = ArrayHelper::remove($options, 'tag', 'div');
$this->parts['{beginWrapper}'] = Html::beginTag($tag, $options);
$this->parts['{endWrapper}'] = Html::endTag($tag);
}
if ($this->label === false) {
$this->parts['{label}'] = '';
$this->parts['{beginLabel}'] = '';
$this->parts['{labelTitle}'] = '';
$this->parts['{endLabel}'] = '';
} elseif (!isset($this->parts['{beginLabel'])) {
$this->parts['{beginLabel}'] = Html::beginTag('label', $this->labelOptions);
$this->parts['{endLabel}'] = Html::endTag('label');
$attribute = Html::getAttributeName($this->attribute);
$this->parts['{labelTitle}'] = Html::encode($this->label ? $this->label : $this->model->getAttributeLabel($attribute));
}
if ($this->inputTemplate) {
$input = isset($this->parts['{input}']) ? $this->parts['{input}'] : Html::activeTextInput($this->model, $this->attribute, $this->inputOptions);
$this->parts['{input}'] = strtr($this->inputTemplate, ['{input}' => $input]);
}
}
return parent::render($content);
}
示例2: renderInput
/**
*
* @param \yii\db\ActiveRecord $model
* @param integer $index
* @return type
*/
protected function renderInput($model, $index)
{
if ($this->inputOptions instanceof \Closure) {
$options = call_user_func($this->inputOptions, $model, $index);
} else {
$options = $this->inputOptions;
}
$options['data-attribute'] = $this->attribute;
if ($this->_isList) {
if ($this->inputItems instanceof \Closure) {
$items = call_user_func($this->inputItems, $model, $index);
} else {
$items = $this->inputItems;
}
if ($model->hasAttribute($this->attribute)) {
return call_user_func(['yii\\helpers\\Html', 'active' . $this->inputType], $model, "[{$index}]{$this->attribute}", $items, $options);
} else {
$name = Html::getInputName($model, "[{$index}]{$this->attribute}");
$value = ArrayHelper::remove($options, 'value');
return call_user_func(['yii\\helpers\\Html', $this->inputType], $name, $value, $items, $options);
}
} else {
if ($model->hasAttribute($this->attribute)) {
return call_user_func(['yii\\helpers\\Html', 'active' . $this->inputType], $model, "[{$index}]{$this->attribute}", $options);
} else {
$name = Html::getInputName($model, "[{$index}]{$this->attribute}");
$value = ArrayHelper::remove($options, 'value');
return call_user_func(['yii\\helpers\\Html', $this->inputType], $name, $value, $options);
}
}
}
示例3: renderItem
/**
* Renders a widget's item.
*
* @param string|array $item
* the item to render.
* @return string the rendering result.
* @throws InvalidConfigException
*/
public function renderItem($item)
{
if (is_string($item)) {
return $item;
}
if (!isset($item['label'])) {
throw new InvalidConfigException("The 'label' option is required.");
}
$options = ArrayHelper::getValue($item, 'options', []);
$items = ArrayHelper::getValue($item, 'items');
if (isset($item['active'])) {
$active = ArrayHelper::remove($item, 'active', false);
} else {
$active = $this->isItemActive($item);
}
if ($items !== null) {
$item['linkOptions'] = ['class' => 'dropdown-toggle'];
if (is_array($items)) {
if ($this->activateItems) {
$items = $this->isChildActive($items, $active);
}
$items = $this->renderSubItems($items, $item);
}
}
if ($this->activateItems && $active) {
Html::addCssClass($options, 'active');
}
$linkHtml = $this->renderItemLink($item);
$arrowHtml = Html::tag('b', '', ['class' => 'arrow']);
return Html::tag('li', $linkHtml . $arrowHtml . $items, $options);
}
示例4: begin
/**
* @inheritdoc
*/
public function begin()
{
if (!$this->formConfig['enableClientScript']) {
$clientOptions = $this->getClientOptions();
if (!empty($clientOptions)) {
if ($this->form) {
$this->form->attributes[] = $clientOptions;
}
}
}
$inputID = Html::getInputId($this->model, $this->attribute);
$attribute = Html::getAttributeName($this->attribute);
$options = $this->options;
$class = isset($options['class']) ? [$options['class']] : [];
$class[] = "field-{$inputID}";
if ($this->model->isAttributeRequired($attribute)) {
$class[] = $this->form ? $this->form->requiredCssClass : $this->formConfig['requiredCssClass'];
}
if ($this->model->hasErrors($attribute)) {
$class[] = $this->form ? $this->form->errorCssClass : $this->formConfig['errorCssClass'];
}
$options['class'] = implode(' ', $class);
$tag = ArrayHelper::remove($options, 'tag', 'div');
return Html::beginTag($tag, $options);
}
示例5: run
public function run()
{
echo Html::beginTag('img', $this->options);
$this->options['src'] = ArrayHelper::remove($this->options, 'data-src');
Html::removeCssClass($this->options, 'lazy');
echo '<noscript>' . Html::beginTag('img', $this->options) . '</noscript>';
}
示例6: icon
/**
* Composes icon HTML for bootstrap Glyphicons.
* @param string $name icon short name, for example: 'star'
* @param array $options the tag options in terms of name-value pairs. These will be rendered as
* the attributes of the resulting tag. There are also a special options:
*
* - tag: string, tag to be rendered, by default 'span' is used.
* - prefix: string, prefix which should be used to compose tag class, by default 'glyphicon glyphicon-' is used.
*
* @return string icon HTML.
* @see http://getbootstrap.com/components/#glyphicons
*/
public static function icon($name, $options = [])
{
$tag = ArrayHelper::remove($options, 'tag', 'span');
$classPrefix = ArrayHelper::remove($options, 'prefix', 'glyphicon glyphicon-');
static::addCssClass($options, $classPrefix . $name);
return static::tag($tag, '', $options);
}
示例7: _setView
private function _setView($config)
{
$selectedTheme = ArrayHelper::remove($config, 'selectedTheme');
$themesBasePath = ArrayHelper::remove($config, 'themesBasePath', '@appitnetwork/wpthemes/wordpress/wp-content/themes');
$path = Yii::getAlias($themesBasePath) . DIRECTORY_SEPARATOR . $selectedTheme;
if ($selectedTheme && is_dir($path)) {
$wpThemesBasePath = ArrayHelper::remove($config, 'wpThemesBasePath', $themesBasePath);
$themesBaseUrl = ArrayHelper::remove($config, 'themesBaseUrl', '@web/../vendor/appitnetwork/yii2-wordpress-themes/src/wordpress/wp-content/themes');
$wpThemesBaseUrl = ArrayHelper::remove($config, 'wpThemesBaseUrl', $themesBaseUrl);
$originalTheme = Yii::$app->view->theme;
Yii::$app->set('view', Yii::createObject(['class' => 'appitnetwork\\wpthemes\\components\\WP_View', 'theme' => ['class' => 'appitnetwork\\wpthemes\\components\\WP_Theme', 'baseUrl' => $themesBaseUrl . '/' . $selectedTheme, 'basePath' => $themesBasePath . '/' . $selectedTheme, 'selectedTheme' => $selectedTheme, 'themesBaseUrl' => $themesBaseUrl, 'themesBasePath' => $themesBasePath, 'wpThemesBaseUrl' => $wpThemesBaseUrl, 'wpThemesBasePath' => $wpThemesBasePath], 'originalTheme' => $originalTheme]));
$wpThemesLayout = '@appitnetwork/wpthemes/views/layouts/main';
Yii::$app->layout = $wpThemesLayout;
$generatorIsWordPress = ArrayHelper::remove($config, 'generatorIsWordPress', false);
if ($generatorIsWordPress) {
ArrayHelper::remove($config, 'generator');
ArrayHelper::remove($config, 'generatorUrl');
$this->generator = 'WordPress';
$this->generatorUrl = 'https://wordpress.org/';
} else {
$this->generator = ArrayHelper::remove($config, 'generator', 'Yii2 with WordPress Themes');
$this->generatorUrl = ArrayHelper::remove($config, 'generatorUrl', 'https://github.com/AppItNetwork/yii2-wordpress-themes/');
}
}
return $config;
}
示例8: search
/**
* Sends a request to the _search API and returns the result.
* @param array $options
* @throws ErrorResponseException
* @return mixed
*/
public function search($options = [])
{
$url = $this->index . Inflector::id2camel(ArrayHelper::remove($options, 'scenario', 'search'));
$query = $this->queryParts;
$options = array_merge($query, $options);
return $this->db->post($url, $options);
}
示例9: createField
/**
* @param static|array|string $config объект BaseField, имя класса, конфигурационный массив
* @return static
*/
public static function createField($config)
{
if (is_string($config)) {
$instance = Yii::createObject(['class' => $config]);
} elseif (is_array($config)) {
//если в конфиге не указан клас поля, то определяем его по типу
if (!isset($config['class'])) {
//если не указан тип то используется по умолчанию 'text'
$field = ArrayHelper::remove($config, 'field', 'text');
$fieldConfig = self::$builtInFields[$field];
if (is_array($fieldConfig)) {
//если конфигурация типа задана массивом то мерджим с текущей конфигурацией
$config = array_merge($fieldConfig, $config);
} else {
//если строка то подставляем ее в качестве имени класса в конфигурацию
$config['class'] = $fieldConfig;
}
}
$instance = Yii::createObject($config);
} else {
//предполагается что дан объект BaseField
$instance = $config;
}
if (!$instance instanceof self) {
throw new InvalidParamException(__CLASS__ . ' object was not created.');
}
return $instance;
}
示例10: run
/**
*
*/
public function run()
{
$view = $this->getView();
$this->registerScript($view);
if ($this->hasModel()) {
if ($this->label) {
$label = $this->label;
} else {
$label = Html::encode($this->model->getAttributeLabel(Html::getAttributeName($this->attribute)));
}
$tag = ArrayHelper::remove($this->textOptions, 'tag', 'span');
$text = Html::tag($tag, $label, $this->textOptions);
$this->options['label'] = $text;
$checkbox = Html::activeCheckbox($this->model, $this->attribute, $this->options);
} else {
$checkbox = Html::checkbox($this->name, $this->value, $this->options);
if ($this->label) {
$tag = ArrayHelper::remove($this->textOptions, 'tag', 'span');
$text = Html::tag($tag, $this->label, $this->textOptions);
$checkbox = Html::tag('label', $checkbox . ' ' . $text, $this->labelOptions);
}
}
$input = Html::tag('div', $checkbox, $this->containerOptions);
echo strtr($this->template, ['{input}' => $input]);
}
示例11: run
public function run()
{
$rows = [];
$i = 0;
foreach ($this->attributes as $attribute) {
$rows[] = $this->renderAttribute($attribute, $i++);
}
$t = [];
$len = count($rows);
for ($j = 0; $j < $len; $j++) {
if (fmod($j, $this->columns) == 0) {
$rows[$j] = '<tr>' . $rows[$j];
} elseif (fmod($j, $this->columns) == $this->columns - 1) {
$rows[$j] .= '</tr>';
}
if ($j == $len - 1) {
$_len = $this->columns - (fmod($j, $this->columns) + 1);
for ($i = 0; $i < $_len; $i++) {
$rows[$j] .= strtr($this->template, ['{label}' => ' ', '{value}' => ' ']);
}
$rows[$j] .= '</tr>';
}
}
$options = $this->options;
$tag = ArrayHelper::remove($options, 'tag', 'table');
echo Html::tag($tag, implode("\n", $rows), $options);
}
示例12: normalizeColumns
/**
*
* @return array
*/
protected function normalizeColumns()
{
$columns = [];
$frozenColumns = [];
$filters = [];
foreach ($this->columns as $column) {
if (is_string($column)) {
$column = $this->createColumn($column);
}
$field = $column['field'];
$filter = ArrayHelper::remove($column, 'filter', []);
if ($filter !== false) {
$filter['field'] = $field;
$filters[] = $filter;
}
if (ArrayHelper::remove($column, 'frozen')) {
$frozenColumns[] = $column;
} else {
$columns[] = $column;
}
}
$this->clientOptions['columns'] = [$columns];
$this->clientOptions['frozenColumns'] = [$frozenColumns];
if ($this->enableFilter) {
$this->clientOptions['filterRules'] = $filters;
}
}
示例13: __call
/**
* @param string $name
* @param array $params
* @return mixed|object
*/
public function __call($name, $params)
{
$query = strpos($name, 'Query');
$static = strpos($name, 'static');
if ($static === 0) {
$property = mb_substr($name, 6);
} else {
if ($query !== false) {
$property = mb_substr($name, 6, -5);
} else {
$property = mb_substr($name, 6);
}
}
$property = lcfirst($property) . 'Class';
if ($static === 0) {
$method = ArrayHelper::remove($params, '0', 'className');
return forward_static_call_array([$this->{$property}, $method], $params);
}
if ($query) {
$method = ArrayHelper::remove($params, '0', 'find');
return forward_static_call_array([$this->{$property}, $method], $params);
}
if (isset($this->{$property})) {
$config = [];
if (isset($params[0]) && is_array($params[0])) {
$config = $params[0];
}
$config['class'] = $this->{$property};
return Yii::createObject($config);
}
return parent::__call($name, $params);
}
示例14: getTree
/**
* Returns all of categories as tree
*
* @param array $options
* @return mixed
*/
public static function getTree(array $options = [])
{
$depth = ArrayHelper::remove($options, 'depth', -1);
/** @var \Closure $filter */
$filter = ArrayHelper::remove($options, 'filter', function ($item) {
return true;
});
/** @var Category[] $list */
$list = self::find()->all();
$list = ArrayHelper::remove($options, 'list', $list);
$getChildren = function ($id, $depth) use($list, &$getChildren, $filter) {
$result = [];
foreach ($list as $item) {
if ((int) $item['parent_id'] === (int) $id) {
$r = ['title' => $item['title'], 'sort_order' => $item['sort_order'], 'id' => $item['id']];
$c = $depth ? $getChildren($item['id'], $depth - 1) : null;
if (!empty($c)) {
$r['children'] = $c;
}
if ($filter($r)) {
$result[] = $r;
}
}
}
usort($result, function ($a, $b) {
return $a['sort_order'] > $b['sort_order'];
});
return $result;
};
return $getChildren(0, $depth);
}
示例15: run
public function run()
{
$id = $this->options['id'];
$options = Json::htmlEncode($this->getClientOptions());
$view = $this->getView();
EditorGridViewAsset::register($view);
$view->registerJs("jQuery('#{$id}').yiiGridView({$options});\$(document).off('change.yiiGridView keydown.yiiGridView');");
if ($this->showOnEmpty || $this->dataProvider->getCount() > 0) {
$content = preg_replace_callback("/{\\w+}/", function ($matches) {
$content = $this->renderSection($matches[0]);
return $content === false ? $matches[0] : $content;
}, $this->layout);
} else {
$content = $this->renderEmpty();
}
$options = $this->options;
$tag = ArrayHelper::remove($options, 'tag', 'div');
echo Html::tag($tag, $content, $options);
foreach ($this->columns as $column) {
if (isset($column->attribute) && $column->editable) {
$models = $this->dataProvider->getModels();
if (($model = reset($models)) instanceof Model) {
$name = Html::getInputName($model, $column->attribute);
} else {
$name = $column->attribute;
}
$attributeName = $column->attribute;
$view->registerJs("\$('.{$attributeName}').editable({\n placement:'right',\n ajaxOptions: {\n type: 'GET',\n dataType: 'json'\n },\n success: function(response, newValue) {\n if(response.status=='success')\n {\n return jQuery('#{$this->options['id']}').yiiGridView('applyFilter');\n }\n else\n {\n return response.msg;\n }\n },\n params: function(rawParams) {\n var params = {};\n params['{$name}']=rawParams.value;\n params['pk']=rawParams.pk;\n return params;\n }\n });");
}
}
}