Why not returning full value on Laravel -Guzzle - json

I am trying to return the JSON data from a third party API with Laravel-Guzzle. Everything is working but the value is different it's like some kind missing characters specially on images.
Here's Laravel-Guzzle code :
$client = new \GuzzleHttp\Client();
$request = $client->request('GET',
'https://targetweb.com/api/v2/search_items/?', [
'query' => [
'by' => 'relevancy',
'keyword' => 'productx',
'limit' => 50,
'newest' => 0,
'order' => 'desc',
'page_type' => 'search',
'version' => 2
]
]);
$array = json_decode($request->getBody()->getContents(), true);
$nArrItems = count($array['items']);
for ($x=0;$x<$nArrItems;$x++){
echo $array['items'][$x]['name'].'<br/>';
$nImages = count($array['items'][$x]['images']);
for($z=0;$z<$nImages;$z++){
echo $array['items'][$x]['images'][$z]."<br/>";
}
}
Result on my browser running Laravel
It has same result as with API tester
Result API tester
but if I compare it(the above) with chrome inspect
Chrome inspect
in my browser : "309adc074bfeef9ad6d13561ef2","70eb....
in API tester : "images":["309adc074bfeef9ad6d13561ef2","70eb....
in Chrome inspect : "images":["309adc074bfeef9ad6d13561ef2e3ad1","70eb....
It has missing characters that does not show in my browser & API Tester.
Any help as why this is happening would be greatly appreciated.

Related

Yii2 Two different way for breadcrumbs

I have a gii generated view.php page, which can be reached from two different paths, but the breadcrumbs is the same. Anyone know how to fix?
Let me explain: I have the view.php view which shows the summary of the report made and can be reached from two paths:
when I create a new report and therefore the path should be HOME / CREATION / VIEW;
and also from a section that shows the user the summary of the reports she sent and therefore the breadcrumbs should be HOME / SUMMARY / VIEW.
You have 2 options to know where it came from:
Send a query variable on each link or in the redirection to manually build the breadcumb. Like: $value = Yii::$app->request->getQueryParam('breadcumb')
Other option is to get the referrer url. And base on the value you can pass it to the switch. You can get referrer's url using: $value = Yii::$app->request->getReferrer().
Then do a switch to build the link:
switch(value) {
case 'creation':
$label = 'CREATION';
$url = 'url_of_creation';
break;
case 'summary':
$label = 'SUMMARY';
$url = 'url_of_summary';
break;
}
Then just do something like this:
$this->params['breadcrumbs'][] = ['label' => $label, 'url' => $url];
This is a short breadcrum solution using match():
$this->params['breadcrumbs'][] = match($path) {
'creation' => ['label' => 'Creation', 'url' => Url::to['creation'],
'summary' => ['label' => 'Summary', 'url' => Url::to['summary'],
};
$path should either be set in the controller or determined by Yii::$app->request->getReferrer().
Please note, that this requires PHP8.

Search and view Elasticsearch results from an HTML

I am currently working on a project and as the title suggests, what I want to do is to be able to search from an HTML a cluster already uploaded on elasticsearch and preview the results back in the HTML.
I thought of using Logstash to send the search input from HTML to elasticsearch but I can't figure a way of viewing those results back in the HTML. In general what I want to do, is to be able to work with elasticsearch the way kibana does, but from a website.
Appreciate any possible help :)
use php-elastic official library(https://github.com/elastic/elasticsearch-php).
You can use the following code to get the search result:
$this->client = ClientBuilder::create()->setHosts(["ELASTICSEARCH_HOST:ELASTICSEARCH_PORT"])->build();
$queryBody = ["match_all" => new \stdClass()];
if($search) {
$queryBody = [
"match" => [
"_all" => $search
]
];
}
$params = [
"from" => $page * $this->pageSize, // if you want data for pagination
"size" => $this->pageSize, // if you want data for pagination
"index" => $index,
"type" => $type,
"_source_include" => $fields, // Your required field array
"body" => [
"query" => $queryBody
]
];
//Get the search result
$response = $this->client->search($params);

Why my listview not found any record in yii2?

I have a dataprovider to search a world but my listview does not display any record? How can i send this query object to listview?
every thing in my webpage is worked very good but at the output my list view show "not found any result" this mean my list view code is no have problem . problem is in my dataprovider and this query beacuse i customize that
my controller:
$query = new Query();
$dataProvidersearch=new ActiveDataProvider([
'query'=>$query->from('tbl_post')->Where(['like', 'title', $search])-
>andWhere(['like', 'en_title', $search])->andWhere(['like', 'content', $search])->andWhere(['like', 'en_content', $search]),
]);
this is my list view in my view:
$posts = $model->getModels();
echo ListView::widget([
'dataProvider'=>$posts,
'itemView'=>'search',
'summary' => '',
'itemOptions' => [
'tag' => false
],
]);
I'm not sure you have enough code here for someone to help. Even something simple like a listview could consist of a view, a controller, and two model files and your code could be failing at any of these points. You may have simply forgot to include the listview library at the top of your view, but we can't see that in your current example.
What I would recommend is using Gii to generate a listview. It is simple to do and once you have it created, you can study the code to see where you went wrong. You can see how to get started generating code with Gii here: http://www.yiiframework.com/doc-2.0/guide-start-gii.html
ANSWER FROM COMMENTS: Replace andWhere with orWhere, no results are found because no record can match 'title' and 'en_title' and 'content' and 'en_content'.
You are submitting $posts as 'dataProvider' while it should be dataProvidersearch
Instead of:
$posts = $model->getModels();
echo ListView::widget([
'dataProvider'=>$posts,
'itemView'=>'search',
'summary' => '',
'itemOptions' => [
'tag' => false
],
];
Should be:
$posts = $model->getModels();
echo ListView::widget([
'dataProvider'=>$dataProvidersearch,
'itemView'=>'search',
'summary' => '',
'itemOptions' => [
'tag' => false
],
];

yii2 mpdf render html reached max memory size

I trying to render a very big pdf with mdpdf on Yii2 framework.
I genereate an html page, but when i call the render function, php run out of memory.
I don't wanna expand the memory_limit ini settings (256M is more than necessary).
I use this configuration, $html contains my huge code:
$pdf = new Pdf([
'mode' => Pdf::MODE_CORE,
'content' => $html,
'options' => [
'title' => 'Report',
],
'marginHeader' => 2,
]);
return $pdf;
Maybe there's a way to render step to step the pdf?
In Yii2 mpdf the content is normally a renderPartial for a form layout
and the renderPartial is populated by one or more models that are the result of query eg:
$models = MyModel::find()->all();
$content = $this->renderPartial('_mpdf_report_scheda', [
'model' => $models,
]);
$pdf = new Pdf([
.......
'content' => $content,
could be that in your case the result of the query retrieve to much rows so you could spliet you content in a part
eg: using limit() and offset()
$models = MyModel::find()
->limit(20)
->all();
$models = MyModel::find()
->limit(20)
.>offset(20)
->all();
and launch the pdf for parts

Add groups as collaborator

I am trying to add a group as a collaborator of a folder using the BOX.net api but i can't.
I am not having any issues to add users, but i couldn't add groups.
I am doing it as they say to do it: {id: "GROUP_ID"} but i am getting a "NOT FOUND" error.
I checked the group and folder id and they are both correct.
Did anyone face this issue before? Is there somebody who can help me with this? I would really appreciate it.
Thanks in advance,
Regards,
Marcelo
You have to be a group administrator on the Box Enterprise in order to manage groups. You may need to ask your Box admin to add you as a co-admin, and give you the "manage groups" permission.
Make sure you pass in "type":"group" in the accessible_by field in addition to "id":"GROUP_ID".
This should be documented soon.
Here's a small example of adding a group as collaborator (PHP). This is done via the V2 API, in case you're using the V1 api (saw you mentioned box.net's api, which is the V1 api).
function addGroupColaborator($folderId, $groupId, $accessType, $accessToken){
$options = array(
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_VERBOSE => true,
CURLOPT_HEADER => false,
CURLINFO_HEADER_OUT => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => false
);
$url = 'https://api.box.com/2.0/collaborations?notify=false';
$options[CURLOPT_HTTPHEADER] = array ("Authorization: Bearer ".$accessToken);
$postf = array(
"item" => array(
"id" => $folderId,
"type" => "folder"
),
"accessible_by" => array(
"id" => $groupId,
"type" => 'group'
),
"role" => $accessType
);
$options[CURLOPT_POST] = true;
$options[CURLOPT_POSTFIELDS] = json_encode($postf);
$ch = curl_init($url);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result, true);
}