Convert model collection to json_encodeBenefits of Mage::getSingleton('core/resource_iterator')Fetch value...
Strange behavior in TikZ draw command
Why is participating in the European Parliamentary elections used as a threat?
Hashing password to increase entropy
Why can't I get pgrep output right to variable on bash script?
Not hide and seek
What is the period/term used describe Giuseppe Arcimboldo's style of painting?
Travelling in US for more than 90 days
Make a Bowl of Alphabet Soup
Why is implicit conversion not ambiguous for non-primitive types?
How do you justify more code being written by following clean code practices?
Writing in a Christian voice
Started in 1987 vs. Starting in 1987
What is the tangent at a sharp point on a curve?
Extract substring according to regexp with sed or grep
Why doesn't Gödel's incompleteness theorem apply to false statements?
Highest stage count that are used one right after the other?
Are hand made posters acceptable in Academia?
How to track Account Description field changes in Field history Tracking?
How to get directions in deep space?
Index matching algorithm without hash-based data structures?
"Marked down as someone wanting to sell shares." What does that mean?
Showing mass murder in a kid's book
Does capillary rise violate hydrostatic paradox?
How would a solely written language work mechanically
Convert model collection to json_encode
Benefits of Mage::getSingleton('core/resource_iterator')Fetch value from collection without foreach loopFilter Collection with result of previous collectionPut another collection as the values of “WHERE … IN (…)”Magento pagination not working with custom objectsWorking with collections, should I use function getData()Foreach Loop Pulling Wrong Value From CollectionMagento Iterator Vs Foreach Loop How to return an array?Unable to load the collection in DataProvider by matching values in arrayConvert(re-write) array_filter code into foreach loop
Currently I'm converting my collection data to json_encode
like this:
$collections = $this->modelFactory->create()->getCollection()
->addFieldToFilter('status','1');
$result = array();
foreach($collections as $collection){
$result[] = $collection->getData();
}
return json_encode($result);
The problem is I need to loop for each collection to get the array data so that I can put it inside json_encode
function, is there a way I can convert the collection result to json_encode
without looping?
magento2 collection model performance json
add a comment |
Currently I'm converting my collection data to json_encode
like this:
$collections = $this->modelFactory->create()->getCollection()
->addFieldToFilter('status','1');
$result = array();
foreach($collections as $collection){
$result[] = $collection->getData();
}
return json_encode($result);
The problem is I need to loop for each collection to get the array data so that I can put it inside json_encode
function, is there a way I can convert the collection result to json_encode
without looping?
magento2 collection model performance json
add a comment |
Currently I'm converting my collection data to json_encode
like this:
$collections = $this->modelFactory->create()->getCollection()
->addFieldToFilter('status','1');
$result = array();
foreach($collections as $collection){
$result[] = $collection->getData();
}
return json_encode($result);
The problem is I need to loop for each collection to get the array data so that I can put it inside json_encode
function, is there a way I can convert the collection result to json_encode
without looping?
magento2 collection model performance json
Currently I'm converting my collection data to json_encode
like this:
$collections = $this->modelFactory->create()->getCollection()
->addFieldToFilter('status','1');
$result = array();
foreach($collections as $collection){
$result[] = $collection->getData();
}
return json_encode($result);
The problem is I need to loop for each collection to get the array data so that I can put it inside json_encode
function, is there a way I can convert the collection result to json_encode
without looping?
magento2 collection model performance json
magento2 collection model performance json
edited 6 mins ago
ABHISHEK TRIPATHI
1,9101726
1,9101726
asked Jan 3 '18 at 6:45
nortonuser nortonuser
381114
381114
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Try this:
$result = $collections->toArray();
return json_encode($result);
or
$result = $collections->getData();
return json_encode($result);
add a comment |
You can simply get the collection data & encode it to json, please follow the below code.
protected $jsonHelper;
public function __construct(MagentoFrameworkJsonHelperData $jsonHelper)
{
$this->jsonHelper = $jsonHelper;
}
...
public function encodeSomething()
{
$collections = $this->modelFactory->create()->getCollection()
->addFieldToFilter('status','1');
$result = $collection->getData();
return $this->jsonHelper->jsonEncode($result);
}
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f207835%2fconvert-model-collection-to-json-encode%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try this:
$result = $collections->toArray();
return json_encode($result);
or
$result = $collections->getData();
return json_encode($result);
add a comment |
Try this:
$result = $collections->toArray();
return json_encode($result);
or
$result = $collections->getData();
return json_encode($result);
add a comment |
Try this:
$result = $collections->toArray();
return json_encode($result);
or
$result = $collections->getData();
return json_encode($result);
Try this:
$result = $collections->toArray();
return json_encode($result);
or
$result = $collections->getData();
return json_encode($result);
answered Jan 3 '18 at 6:47
Nero PhungNero Phung
9041620
9041620
add a comment |
add a comment |
You can simply get the collection data & encode it to json, please follow the below code.
protected $jsonHelper;
public function __construct(MagentoFrameworkJsonHelperData $jsonHelper)
{
$this->jsonHelper = $jsonHelper;
}
...
public function encodeSomething()
{
$collections = $this->modelFactory->create()->getCollection()
->addFieldToFilter('status','1');
$result = $collection->getData();
return $this->jsonHelper->jsonEncode($result);
}
add a comment |
You can simply get the collection data & encode it to json, please follow the below code.
protected $jsonHelper;
public function __construct(MagentoFrameworkJsonHelperData $jsonHelper)
{
$this->jsonHelper = $jsonHelper;
}
...
public function encodeSomething()
{
$collections = $this->modelFactory->create()->getCollection()
->addFieldToFilter('status','1');
$result = $collection->getData();
return $this->jsonHelper->jsonEncode($result);
}
add a comment |
You can simply get the collection data & encode it to json, please follow the below code.
protected $jsonHelper;
public function __construct(MagentoFrameworkJsonHelperData $jsonHelper)
{
$this->jsonHelper = $jsonHelper;
}
...
public function encodeSomething()
{
$collections = $this->modelFactory->create()->getCollection()
->addFieldToFilter('status','1');
$result = $collection->getData();
return $this->jsonHelper->jsonEncode($result);
}
You can simply get the collection data & encode it to json, please follow the below code.
protected $jsonHelper;
public function __construct(MagentoFrameworkJsonHelperData $jsonHelper)
{
$this->jsonHelper = $jsonHelper;
}
...
public function encodeSomething()
{
$collections = $this->modelFactory->create()->getCollection()
->addFieldToFilter('status','1');
$result = $collection->getData();
return $this->jsonHelper->jsonEncode($result);
}
answered 10 mins ago
ABHISHEK TRIPATHIABHISHEK TRIPATHI
1,9101726
1,9101726
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f207835%2fconvert-model-collection-to-json-encode%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown