本文整理汇总了PHP中yii\helpers\ArrayHelper::merge方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayHelper::merge方法的具体用法?PHP ArrayHelper::merge怎么用?PHP ArrayHelper::merge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\ArrayHelper
的用法示例。
在下文中一共展示了ArrayHelper::merge方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
public function init()
{
parent::init();
$this->types = yii\helpers\ArrayHelper::merge($this->defaultTypes, $this->types);
// pre-init string
$this->types['string'] = Yii::createObject($this->types['string']);
}
示例2: behaviors
/**
* @inheritdoc
*/
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['access']['rules'] = ArrayHelper::merge($behaviors['access']['rules'], [['allow' => true, 'actions' => ['index'], 'roles' => ['pageView']], ['allow' => true, 'actions' => ['create'], 'roles' => ['pageCreate']], ['allow' => true, 'actions' => ['update'], 'roles' => ['pageUpdate']], ['allow' => true, 'actions' => ['delete', 'batch-delete'], 'roles' => ['pageDelete']]]);
$behaviors['verbs'] = ['class' => VerbFilter::className(), 'actions' => ['index' => ['get'], 'update' => ['get', 'put', 'post'], 'delete' => ['post', 'delete'], 'batch-delete' => ['post', 'delete']]];
return $behaviors;
}
示例3: run
public function run()
{
if (empty($this->name) && (!empty($this->model) && !empty($this->attribute))) {
$this->name = Html::getInputName($this->model, $this->attribute);
}
if (empty($this->url)) {
$this->url = Url::toRoute(['site/upload']);
}
$options = ['url' => $this->url, 'paramName' => $this->name, 'params' => []];
if (Yii::$app->request->enableCsrfValidation) {
$options['params'][Yii::$app->request->csrfParam] = Yii::$app->request->getCsrfToken();
}
if (!empty($this->message)) {
$message = Html::tag('div', $this->message, $this->messageOptions);
} else {
$message = '';
}
$this->htmlOptions['id'] = $this->id;
$this->options = ArrayHelper::merge($this->options, $options);
echo Html::tag('div', $message, $this->htmlOptions);
$this->registerAssets();
$this->createDropzone();
foreach ($this->eventHandlers as $event => $handler) {
$handler = new \yii\web\JsExpression($handler);
$this->getView()->registerJs($this->dropzoneName . ".on('{$event}', {$handler})");
}
$this->addFiles($this->storedFiles);
$this->decrementMaxFiles(count($this->storedFiles));
if ($this->sortable) {
$options = Json::encode($this->sortableOptions);
$this->getView()->registerJs("jQuery('#{$this->id}').sortable(" . $options . ");");
}
}
示例4: rules
public function rules()
{
$rules = [['phone', 'trim'], ['phone', 'filter', 'filter' => function ($value) {
return str_replace('+', '', $value);
}], ['phone', 'string', 'min' => 11, 'max' => 12]];
return \yii\helpers\ArrayHelper::merge(parent::rules(), $rules);
}
示例5: rules
public function rules()
{
$parentRules = parent::rules();
$childRules = [['nickname', 'string', 'max' => '255'], ['gender', 'integer'], ['identity_num', 'string', 'length' => [15, 18]], ['qq', 'match', 'pattern' => "/^[1-9]*[1-9][0-9]*\$/i"], ['qq', 'string', 'max' => '11'], ['birthday', 'filter', 'filter' => 'strtotime', 'skipOnEmpty' => true]];
$rules = ArrayHelper::merge($parentRules, $childRules);
return $rules;
}
示例6: registerKCFinder
/**
* Registers KCFinder
*/
protected function registerKCFinder()
{
$register = KCFinderAsset::register($this->view);
$kcfinderUrl = $register->baseUrl;
$browseOptions = ['filebrowserBrowseUrl' => $kcfinderUrl . '/browse.php?opener=ckeditor&type=files', 'filebrowserUploadUrl' => $kcfinderUrl . '/upload.php?opener=ckeditor&type=files'];
$this->clientOptions = ArrayHelper::merge($browseOptions, $this->clientOptions);
}
示例7: actionView
public function actionView($id)
{
$model = new AssignmentForm();
$model->setScenario('auth');
$permissions = [];
$app = [];
$authManager = Yii::$app->authManager;
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
foreach ($model->getAttributes() as $key => $value) {
if (empty($value)) {
$model->{$key} = [];
}
}
//Revokes all roles from a user.
try {
$authManager->revokeAll($id);
//角色
if (is_array($model->roles)) {
foreach ($model->roles as $name) {
$item = $authManager->getRole($name);
$authManager->assign($item, $id);
}
}
//权限
$roles = ArrayHelper::merge($model->permissions, $model->app);
if (is_array($roles)) {
foreach ($roles as $name) {
$item = $authManager->getPermission($name);
$authManager->assign($item, $id);
}
}
} catch (\Exception $e) {
Yii::$app->session->setFlash('fail', $e->getMessage());
$this->refresh();
Yii::$app->end();
}
Yii::$app->session->setFlash('success', '授权成功');
$this->redirect(['index']);
}
$roles = $authManager->getRoles();
$roles = ArrayHelper::map($roles, 'name', 'name');
foreach ($authManager->getPermissions() as $name => $role) {
if ($role->name[0] == '/') {
$permissions[$name] = $role->description;
} elseif (substr($role->name, 0, 3) == 'app') {
$app[$name] = $role->description;
}
}
foreach ($authManager->getAssignments($id) as $name => $item) {
if ($name[0] == '/') {
$model->permissions[$authManager->getPermission($name)->description] = $name;
} elseif (substr($name, 0, 3) == 'app') {
$model->app[$name] = $name;
} else {
$model->roles[$name] = $name;
}
}
$permissions = Tools::serializeRoutes($permissions);
return $this->render('view', ['model' => $model, 'roles' => $roles, 'permissions' => $permissions, 'app' => $app]);
}
示例8: actions
/**
* @inheritdoc
*/
public function actions()
{
return ArrayHelper::merge(parent::actions(), ['index' => ["gridConfig" => ['settingsData' => ['order' => SORT_ASC, 'orderBy' => "priority"]], "columns" => ['name', 'code', ['value' => function (\skeeks\cms\models\CmsContentType $model) {
$contents = \yii\helpers\ArrayHelper::map($model->cmsContents, 'id', 'name');
return implode(', ', $contents);
}, 'label' => 'Контент'], 'priority']]]);
}
示例9: calculate
/**
* Calculates distances and travel times between origins and destinations
*
* @param array $origins Addresses or coordinates
* @param array $destinations Addresses or coordinates
* @param array $params
* @return mixed|null
*/
public function calculate(array $origins, array $destinations, $params = [])
{
$params['origins'] = implode('|', $origins);
$params['destinations'] = implode('|', $destinations);
$this->params = ArrayHelper::merge($this->params, $params);
return parent::request();
}
示例10: init
public function init()
{
parent::init();
try {
$tableSchema = Yii::$app->db->schema->getTableSchema(MenuItem::tableName());
} catch (\yii\db\Exception $e) {
}
if (empty($tableSchema)) {
return;
}
$models = MenuItem::find()->where(['menu_id' => $this->menu])->orderBy(['order_id' => SORT_ASC])->all();
$items = [];
// top menu items
foreach ($models as $model) {
if ($model->parent_id == 0) {
$items[$model->id] = ['label' => $model->title, 'url' => $this->parseRoute($model->route)];
}
}
foreach ($models as $model) {
if (isset($items[$model->parent_id])) {
$items[$model->parent_id]['items'][] = ['label' => $model->title, 'url' => $this->parseRoute($model->route)];
}
}
$this->items = ArrayHelper::merge($items, $this->items);
if (Yii::$app->user->identity && Yii::$app->user->identity->getIsAdmin()) {
$this->items[] = ['label' => 'Admin Panel', 'url' => '/admin'];
}
}
示例11: getManagerOptions
public function getManagerOptions()
{
$options = ['url' => Url::toRoute('connect'), 'customData' => [Yii::$app->request->csrfParam => Yii::$app->request->csrfToken], 'resizable' => false];
if (isset($_GET['CKEditor'])) {
$options['getFileCallback'] = new JsExpression('function(file){ ' . 'window.opener.CKEDITOR.tools.callFunction(' . Json::encode($_GET['CKEditorFuncNum']) . ', file.url); ' . 'window.close(); }');
$options['lang'] = $_GET['langCode'];
}
if (isset($_GET['filter'])) {
if (is_array($_GET['filter'])) {
$options['onlyMimes'] = $_GET['filter'];
} else {
$options['onlyMimes'] = [$_GET['filter']];
}
}
if (isset($_GET['lang'])) {
$options['lang'] = $_GET['lang'];
}
if (isset($_GET['callback'])) {
if (isset($_GET['multiple'])) {
$options['commandsOptions']['getfile']['multiple'] = true;
}
$options['getFileCallback'] = new JsExpression('function(file){ ' . 'if (window!=window.top) {var parent = window.parent;}else{var parent = window.opener;}' . 'if(parent.mihaildev.elFinder.callFunction(' . Json::encode($_GET['callback']) . ', file))' . 'window.close(); }');
}
if (!isset($options['lang'])) {
$options['lang'] = ElFinder::getSupportedLanguage(Yii::$app->language);
}
if (!empty($this->disabledCommands)) {
$options['commands'] = new JsExpression('ElFinderGetCommands(' . Json::encode($this->disabledCommands) . ')');
}
return ArrayHelper::merge($options, $this->managerOptions);
}
示例12: getAvailableApis
/**
* Function return array map for drop down list
* @return array
*/
public static function getAvailableApis()
{
static::getEnabledApiId();
$all = static::find()->all();
$map = ArrayHelper::map($all, 'id', 'name');
return ArrayHelper::merge([0 => Yii::t('app', 'Not selected')], $map);
}
示例13: init
public function init()
{
if (!is_array($this->formConfig)) {
$this->formConfig = [];
}
if (is_array($this->formConfig)) {
$this->formConfig = ArrayHelper::merge(static::getFormConfig(), $this->formConfig);
}
if (!is_array($this->inputConfig)) {
$this->inputConfig = [];
}
if (is_array($this->inputConfig)) {
$this->inputConfig = ArrayHelper::merge(static::getInputConfig(), $this->inputConfig);
}
if (!is_array($this->submitConfig)) {
$this->submitConfig = [];
}
if (is_array($this->submitConfig)) {
$this->submitConfig = ArrayHelper::merge(static::getSubmitConfig(), $this->submitConfig);
}
if (empty($this->model)) {
$this->model = new SearchForm();
}
$this->registerTranslations();
}
示例14: run
public function run()
{
$blockId = 'block_' . $this->id;
$this->view->beginBlock($blockId);
$inputFile = InputFile::begin(ArrayHelper::merge(['model' => $this->model, 'attribute' => $this->attribute, 'name' => $this->name, 'value' => $this->value], $this->fileInputOptions));
$inputId = $inputFile->options['id'];
$previewId = 'media-' . $inputId;
InputFile::end();
$this->view->endBlock();
$replace['{input}'] = $this->view->blocks[$blockId];
$replace['{img}'] = Html::tag('div', '', ['class' => 'form-media-preview', 'id' => $previewId]);
echo strtr($this->template, $replace);
$this->view->registerJs(<<<JS
\$('#{$inputId}').change(function() {
var src = \$(this).val();
if (src != '') {
var img = \$('<img/>').attr('src', src);
\$('#{$previewId}').wrapInner(img);
} else {
\$('#{$previewId}').empty();
}
}).change();
JS
);
}
示例15: __call
public function __call($name, $arguments)
{
$id = md5(microtime());
$request = ['jsonrpc' => '2.0', 'method' => $name, 'params' => $arguments, 'id' => $id];
$jsonRequest = json_encode($request);
$ctx = stream_context_create(\yii\helpers\ArrayHelper::merge(['http' => ['method' => 'POST', 'header' => "Content-Type: application/json-rpc\r\n", 'content' => $jsonRequest]], $this->streamContext));
$jsonResponse = file_get_contents($this->url, false, $ctx);
if ($jsonResponse === '') {
throw new Exception('fopen failed', Exception::INTERNAL_ERROR);
}
$response = json_decode($jsonResponse);
if ($response === null) {
throw new Exception('JSON cannot be decoded', Exception::INTERNAL_ERROR);
}
if ($response->id != $id) {
throw new Exception('Mismatched JSON-RPC IDs', Exception::INTERNAL_ERROR);
}
if (property_exists($response, 'error')) {
throw new Exception($response->error->message, $response->error->code);
} else {
if (property_exists($response, 'result')) {
return $response->result;
} else {
throw new Exception('Invalid JSON-RPC response', Exception::INTERNAL_ERROR);
}
}
}