can someone help me, how I can extend an assiociative array with a variable?
I have a loop (foreach):
foreach($this->getWarehouseListForm() as $wareHouse) {
$wareHouseList[] =
[
"title" => "wareHouse[105]",
"form" => [
"storeId[105]" => [
"type" => "inputText",
"options" => [
"name" => "TSL",
],
],
],
];
}
And I want to extend a object like this:
"sections" => [
[
"title" => 'Schuhe24Assistant.ftpServerTitle',
"description" => 'Schuhe24Assistant.ftpServerDescription',
"form" => [
"ftpServer" => [
'type' => 'text',
'defaultValue' => 'ftp.hisasp2.com',
'options' => [
'name' => 'Schuhe24Assistant.ftpServer',
'required' => true,
]
],
"ftpUser" => [
'type' => 'text',
'defaultValue' => 'username',
'options' => [
'name' => 'Schuhe24Assistant.ftpUser',
'required' => true,
]
],
"ftpPassword" => [
'type' => 'text',
'defaultValue' => 'password',
'options' => [
'name' => 'Schuhe24Assistant.ftpPassword',
#'isPassword' => true,
'required' => true,
],
],
"deleteFiles" => [
'type' => 'toggle',
'defaultValue' => true,
'options' => [
'name' => 'Schuhe24Assistant.deleteFiles',
],
],
],
],
], $wareHouseList
But this code produces nothing (no error output) and the structure check fails in this case. If I remove the variable, the structure check is OK.
Can someone help me out?
Kind regards
Henning
Push your $wareHouseList array into the $sections array in the following ways
$sections['wareHouseList'] = $wareHouseList
It should be working.
Related
By default you can add custom fields to several entities, however I don’t see the order entity in the list of available entities.
Is it possible to add such a field for order so user can fill it in the checkout process, right before sending the order?
And is it possible to add a field for the order and for each order item individually?
Here is one example on how to add to add custom fields to order entity:
$customFieldSetRepository = $this->container->get('custom_field_set.repository');
$customFieldSetRepository->upsert([
[
'name' => self::FIELD_NAME,
// 'global' => true,
'config' => [
'label' => [
'de-DE' => 'Name',
'en-GB' => 'Name'
]
],
'customFields' => [
[
'name' => 'name',
'type' => CustomFieldTypes::DATETIME,
'config' => [
'type' => 'date',
'dateType' => 'date',
'label' => [
'de-DE' => 'Date',
'en-GB' => 'Date'
]
]
],
[
'name' => 'name',
'label' => "Time",
'type' => CustomFieldTypes::TEXT,
'config' => [
'label' => [
'de-DE' => 'name',
'en-GB' => 'name'
]
]
],
[
'name' => 'name',
'label' => "name",
'type' => CustomFieldTypes::INT,
'config' => [
'label' => [
'de-DE' => 'name',
'en-GB' => 'name'
]
]
]
],
'relations' => [[
'entityName' => 'order'
]],
]
], $context);
I made my index with analyzer like in documentation (there).
This is my index create:
$params = [
'index' => 'mytestindex',
'body' => [
'settings' => [
'analysis' => [
'index_analyzer' => [
'my_index_analyzer' => [
'type' => 'custom',
'tokenizer' => 'standard',
'filter' => [
'lowercase',
'mynGram2'
],
],
],
'search_analyzer' => [
'my_search_analyzer' => [
'type' => 'custom',
'tokenizer' => 'standard',
'filter' => [
'standard',
'lowercase',
'mynGram2'
],
],
],
'filter' => [
'mynGram2' => [
'type' => 'nGram',
'min_gram' => 2,
'max_gram' => 20,
],
],
],
'max_ngram_diff' => 50,
],
],
];
$x = $this->obj->indices()->create($params);
Then i try use my analyzer:
$params = [
'index' => 'mytestindex',
'body' => [
'analyzer' => 'my_search_analyzer',
'text' => 'текст проверить чтобы'
],
];
$x = $this->obj->indices()->analyze($params);
But I get this message:
'{"error":{"root_cause":[{"type":"remote_transport_exception","reason":"[PEREGOVOR2][127.0.0.1:9300][indices:admin/analyze[s]]"}],"type":"illegal_argument_exception","reason":"failed
to find analyzer [my_search_analyzer]"},"status":400}'
So... what am I doing wrong? Why can't I use my analyzer and get answer 'failed to find analyze'?
You're not building your analyzer correctly. You only need one analyzer section in your settings:
$params = [
'index' => 'mytestindex',
'body' => [
'settings' => [
'analysis' => [
'analyzer' => [ <--- change this
'my_index_analyzer' => [
'type' => 'custom',
"tokenizer" => "standard",
'filter' => [
"lowercase",
"mynGram2"
],
],
'my_search_analyzer' => [
"type" => "custom",
"tokenizer" => "standard",
'filter' => [
"standard",
"lowercase",
"mynGram2"
],
],
],
'filter' => [
'mynGram2' => [
"type" => "nGram",
"min_gram" => 2,
"max_gram" => 20,
],
],
],
"max_ngram_diff" => "50",
],
],
];
$x = $this->obj->indices()->create($params);
I am trying to implement the suggest function of elasticsearch-php client in my API to suggest people some already existing problems.
I have made index for my problems
'index' => 'newproblemindex',
'body' => [
'settings' => [
'number_of_shards' => 3,
'number_of_replicas' => 2
],
'mappings' => [
'newproblems' => [ // type of index
'_source' => [
'enabled' => true
],
'properties' => [
'title' => [
'type' => 'text',
'analyzer' => 'standard'
],
'description' => [
'type' => 'text',
'analyzer' => 'standard'
], 'suggest' => [
'type' => 'completion'
]
]
]
]
]
But I am unable to find which param fields to use to implement suggest function
'index' => 'newproblemindex',
'body' => [
'try' => [
'text' => $request->search_key,
'completion' => [ 'text' => 'suggest' ]
]
],
I am using laravel and taking search_key as request param but I am getting "invalid_type_name_exception" and when I tried to give the type name, it is again giving me some error.
"suggest" => [
"song-suggest" => [
"prefix" => $request->search_key,
"completion" => ["field" => "suggest"]
]
]
I am getting error "suggest is not a valid param ". Please help
and Thanks in advance.
Here's urlManager configs:
return [
'class' => \yii\web\UrlManager::class,
'enablePrettyUrl' => true,
'showScriptName' => false,
'baseUrl' => '',
'rules' => [
'page/<id:[\\w-_]+>' => 'page/index',
],
];
Here's urlManager using:
$menuItems = [
[
'label' => 'Home',
'url' => Yii::$app->urlManager->createAbsoluteUrl(['/page']),
],
[
'label' => 'About',
'url' => Yii::$app->urlManager->createAbsoluteUrl(['/page', 'id' => 'about']),
],
[
'label' => 'Contact',
'url' => Yii::$app->urlManager->createAbsoluteUrl(['/page', 'id' => 'contact']),
],
];
And here's results from browser:
http://localhost/page?id=about
http://localhost/page?id=contact
What's wrong in my code?
You need to use exact route when creating URLs:
$menuItems = [
[
'label' => 'Home',
'url' => Yii::$app->urlManager->createAbsoluteUrl(['/page']),
],
[
'label' => 'About',
'url' => Yii::$app->urlManager->createAbsoluteUrl(['/page/index', 'id' => 'about']),
],
[
'label' => 'Contact',
'url' => Yii::$app->urlManager->createAbsoluteUrl(['/page/index', 'id' => 'contact']),
],
];
I have a form that accepts a text field and an image, and I would like to be able to validate or filter the images that are uploaded.
I try to follow this tutorial on GitHub (https://github.com/lowtower/zend-expressive2-tutorial)
I am using zend expressive 2. I have this approach:
<?php
namespace Admin\Model\InputFilter;
use Zend\InputFilter\InputFilter;
class EventoInputFilter extends InputFilter
{
public function init()
{
$this->add([
'name' => 'eventoNombre',
'required' => true,
'filters' => [
['name' => 'StripTags'],
['name' => 'StringTrim'],
],
'validators' => [
[
'name' => 'StringLength',
'options' => [
'min' => 5,
'max' => 100,
],
],
],
]);
$this->add([
'name' => 'imagenes[]',
'required' => true,
'validators' => [
[
'name' => 'FileUploadFile'
],
[
'name' => 'FileMimeType',
'options' => [
'mimeType' => ['image/jpeg', 'image/png']
]
],
[
'name' => 'FileIsImage'
],
[
'name' => 'FileImageSize',
'options' => [
'minWidth' => 128,
'minHeight' => 128,
'maxWidth' => 4096,
'maxHeight' => 4096
]
],
],
'filters' => [
[
'name' => 'FileRenameUpload',
'options' => [
'target' => 'public/eventos/',
'useUploadName' => true,
'useUploadExtension' => true,
'overwrite' => true,
'randomize' => false
]
]
],
]);
}
}
but something is wrong and I do not validate it correctly when I upload a correct image.