How to Convert an Object into Array in magento 2Convert mysql query into magento model formatMagento2: Convert DataObject/Array into magento2 Collection?Magento 2 convert object to arrayMagento 2: How to convert product array into collection?Magento 1 - Convert Object into an array valueMagento 2 CMS 404 errorHow to convert this object data into array?Trying to access the admin backend in Magento2 throws a 404 not foundConvert(re-write) array_filter code into foreach looparray convert into Magento 2 collection
How is linear momentum conserved in circular motion?
...and then she held the gun
Are there examples of rowers who also fought?
Justifying Affordable Bespoke Spaceships
Using roof rails to set up hammock
Explicit song lyrics checker
Build a scale without computer
Is using Legacy mode is a bad thing to do?
How to recover a single blank shot from a film camera
What kind of chart is this?
How can I ping multiple IP addresses at the same time?
Kelvin type connection
Is there a polite way to ask about one's ethnicity?
Can a character with the Polearm Master feat make an opportunity attack against an invisible creature that enters their reach?
How can I maintain game balance while allowing my player to craft genuinely useful items?
How valuable is a categorical feature that has a predominant category over all other ones?
How to ask if I can mow my neighbor's lawn
Print the new site header
What is the context for Napoleon's quote "[the Austrians] did not know the value of five minutes"?
How to make all magic-casting innate, but still rare?
How did the European Union reach the figure of 3% as a maximum allowed deficit?
How to write a nice frame challenge?
Digital signature that is only verifiable by one specific person
Got a new frameset, don't know why I need this split ring collar?
How to Convert an Object into Array in magento 2
Convert mysql query into magento model formatMagento2: Convert DataObject/Array into magento2 Collection?Magento 2 convert object to arrayMagento 2: How to convert product array into collection?Magento 1 - Convert Object into an array valueMagento 2 CMS 404 errorHow to convert this object data into array?Trying to access the admin backend in Magento2 throws a 404 not foundConvert(re-write) array_filter code into foreach looparray convert into Magento 2 collection
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
i Need All cms pages in an array I got All in an object but the format i got is not that I expected
$cms = $this->collectionFactory->create()->toOptionIdArray();
echo "<pre>";
print_r($cms->toArray());
exit();
these lines gave me result as
Array
(
[0] => Array
(
[value] => no-route
[label] => 404 Not Found
)
[1] => Array
(
[value] => home
[label] => Home Page
)
[2] => Array
(
[value] => enable-cookies
[label] => Enable Cookies
)
[3] => Array
(
[value] => privacy-policy-cookie-restriction-mode
[label] => Privacy Policy
)
)
but i need this something like
Array
(
[
"value" => 'no-route',
"label" => '404 Not Found'
],
[
"value" => 'home',
"label" => 'Home Page'
],
[
"value" => 'enable-cookies',
"label" => 'Enable Cookies'
],
[
"value" => 'privacy-policy-cookie-restriction-mode',
"label" => 'Privacy Policy'
],
]
i want to add CMS pages in a drop down
$options = [
[
'label' => __('Catagories'),
'value' => [
[
'label' => __('Anchor Catagories'),
'value' => self::CATAGORIES_ANCHORED
],
[
'label' => __('Non-Anchor Catagories'),
'value' => self::NON_CATAGORIES_ANCHORED
]
]
],
[
'label' => __('All Products'),
'value' => [
[
'label' => __('All Product Types'),
'value' => self::PRODUCT_ALL
],
[
'label' => __('Simple Product'),
'value' => self::PRODUCT_SIMPLE
],
[
'label' => __('Virtual Products'),
'value' => self::PRODUCT_VIRUAL
],
[
'label' => __('Downloadable Products'),
'value' => self::PRODUCT_DOWNLOADABLE
],
[
'label' => __('Configureable Products'),
'value' => self::PRODUCT_CONFIGUREABLE
],
[
'label' => __('Grouped Products'),
'value' => self::PRODUCT_GROUPED
],
[
'label' => __('Bundle Products'),
'value' => self::PRODUCT_BUNDLED
]
]
],
[
'label' => __('CMS pages'),
'value' => [
]
]
];
in the CMS pages options
magento2 php
|
show 3 more comments
i Need All cms pages in an array I got All in an object but the format i got is not that I expected
$cms = $this->collectionFactory->create()->toOptionIdArray();
echo "<pre>";
print_r($cms->toArray());
exit();
these lines gave me result as
Array
(
[0] => Array
(
[value] => no-route
[label] => 404 Not Found
)
[1] => Array
(
[value] => home
[label] => Home Page
)
[2] => Array
(
[value] => enable-cookies
[label] => Enable Cookies
)
[3] => Array
(
[value] => privacy-policy-cookie-restriction-mode
[label] => Privacy Policy
)
)
but i need this something like
Array
(
[
"value" => 'no-route',
"label" => '404 Not Found'
],
[
"value" => 'home',
"label" => 'Home Page'
],
[
"value" => 'enable-cookies',
"label" => 'Enable Cookies'
],
[
"value" => 'privacy-policy-cookie-restriction-mode',
"label" => 'Privacy Policy'
],
]
i want to add CMS pages in a drop down
$options = [
[
'label' => __('Catagories'),
'value' => [
[
'label' => __('Anchor Catagories'),
'value' => self::CATAGORIES_ANCHORED
],
[
'label' => __('Non-Anchor Catagories'),
'value' => self::NON_CATAGORIES_ANCHORED
]
]
],
[
'label' => __('All Products'),
'value' => [
[
'label' => __('All Product Types'),
'value' => self::PRODUCT_ALL
],
[
'label' => __('Simple Product'),
'value' => self::PRODUCT_SIMPLE
],
[
'label' => __('Virtual Products'),
'value' => self::PRODUCT_VIRUAL
],
[
'label' => __('Downloadable Products'),
'value' => self::PRODUCT_DOWNLOADABLE
],
[
'label' => __('Configureable Products'),
'value' => self::PRODUCT_CONFIGUREABLE
],
[
'label' => __('Grouped Products'),
'value' => self::PRODUCT_GROUPED
],
[
'label' => __('Bundle Products'),
'value' => self::PRODUCT_BUNDLED
]
]
],
[
'label' => __('CMS pages'),
'value' => [
]
]
];
in the CMS pages options
magento2 php
I think both are same. I dont get any difference between what you get and what you want ..
– Yash Shah
Jun 10 at 6:12
@YashShah check updated question
– Waqar Ali
Jun 10 at 6:19
You can code like this. $options[2]['value'] = $cms->toArray();
– Yash Shah
Jun 10 at 6:25
on toArray() getting errorFatal error: Uncaught Error: Call to a member function toArray() on array
– Waqar Ali
Jun 10 at 6:29
1
In that case, $options[2]['value'] = $cms; should work.
– Yash Shah
Jun 10 at 6:39
|
show 3 more comments
i Need All cms pages in an array I got All in an object but the format i got is not that I expected
$cms = $this->collectionFactory->create()->toOptionIdArray();
echo "<pre>";
print_r($cms->toArray());
exit();
these lines gave me result as
Array
(
[0] => Array
(
[value] => no-route
[label] => 404 Not Found
)
[1] => Array
(
[value] => home
[label] => Home Page
)
[2] => Array
(
[value] => enable-cookies
[label] => Enable Cookies
)
[3] => Array
(
[value] => privacy-policy-cookie-restriction-mode
[label] => Privacy Policy
)
)
but i need this something like
Array
(
[
"value" => 'no-route',
"label" => '404 Not Found'
],
[
"value" => 'home',
"label" => 'Home Page'
],
[
"value" => 'enable-cookies',
"label" => 'Enable Cookies'
],
[
"value" => 'privacy-policy-cookie-restriction-mode',
"label" => 'Privacy Policy'
],
]
i want to add CMS pages in a drop down
$options = [
[
'label' => __('Catagories'),
'value' => [
[
'label' => __('Anchor Catagories'),
'value' => self::CATAGORIES_ANCHORED
],
[
'label' => __('Non-Anchor Catagories'),
'value' => self::NON_CATAGORIES_ANCHORED
]
]
],
[
'label' => __('All Products'),
'value' => [
[
'label' => __('All Product Types'),
'value' => self::PRODUCT_ALL
],
[
'label' => __('Simple Product'),
'value' => self::PRODUCT_SIMPLE
],
[
'label' => __('Virtual Products'),
'value' => self::PRODUCT_VIRUAL
],
[
'label' => __('Downloadable Products'),
'value' => self::PRODUCT_DOWNLOADABLE
],
[
'label' => __('Configureable Products'),
'value' => self::PRODUCT_CONFIGUREABLE
],
[
'label' => __('Grouped Products'),
'value' => self::PRODUCT_GROUPED
],
[
'label' => __('Bundle Products'),
'value' => self::PRODUCT_BUNDLED
]
]
],
[
'label' => __('CMS pages'),
'value' => [
]
]
];
in the CMS pages options
magento2 php
i Need All cms pages in an array I got All in an object but the format i got is not that I expected
$cms = $this->collectionFactory->create()->toOptionIdArray();
echo "<pre>";
print_r($cms->toArray());
exit();
these lines gave me result as
Array
(
[0] => Array
(
[value] => no-route
[label] => 404 Not Found
)
[1] => Array
(
[value] => home
[label] => Home Page
)
[2] => Array
(
[value] => enable-cookies
[label] => Enable Cookies
)
[3] => Array
(
[value] => privacy-policy-cookie-restriction-mode
[label] => Privacy Policy
)
)
but i need this something like
Array
(
[
"value" => 'no-route',
"label" => '404 Not Found'
],
[
"value" => 'home',
"label" => 'Home Page'
],
[
"value" => 'enable-cookies',
"label" => 'Enable Cookies'
],
[
"value" => 'privacy-policy-cookie-restriction-mode',
"label" => 'Privacy Policy'
],
]
i want to add CMS pages in a drop down
$options = [
[
'label' => __('Catagories'),
'value' => [
[
'label' => __('Anchor Catagories'),
'value' => self::CATAGORIES_ANCHORED
],
[
'label' => __('Non-Anchor Catagories'),
'value' => self::NON_CATAGORIES_ANCHORED
]
]
],
[
'label' => __('All Products'),
'value' => [
[
'label' => __('All Product Types'),
'value' => self::PRODUCT_ALL
],
[
'label' => __('Simple Product'),
'value' => self::PRODUCT_SIMPLE
],
[
'label' => __('Virtual Products'),
'value' => self::PRODUCT_VIRUAL
],
[
'label' => __('Downloadable Products'),
'value' => self::PRODUCT_DOWNLOADABLE
],
[
'label' => __('Configureable Products'),
'value' => self::PRODUCT_CONFIGUREABLE
],
[
'label' => __('Grouped Products'),
'value' => self::PRODUCT_GROUPED
],
[
'label' => __('Bundle Products'),
'value' => self::PRODUCT_BUNDLED
]
]
],
[
'label' => __('CMS pages'),
'value' => [
]
]
];
in the CMS pages options
magento2 php
magento2 php
edited yesterday
Aasim Goriya
3,19211141
3,19211141
asked Jun 10 at 5:57
Waqar AliWaqar Ali
11011
11011
I think both are same. I dont get any difference between what you get and what you want ..
– Yash Shah
Jun 10 at 6:12
@YashShah check updated question
– Waqar Ali
Jun 10 at 6:19
You can code like this. $options[2]['value'] = $cms->toArray();
– Yash Shah
Jun 10 at 6:25
on toArray() getting errorFatal error: Uncaught Error: Call to a member function toArray() on array
– Waqar Ali
Jun 10 at 6:29
1
In that case, $options[2]['value'] = $cms; should work.
– Yash Shah
Jun 10 at 6:39
|
show 3 more comments
I think both are same. I dont get any difference between what you get and what you want ..
– Yash Shah
Jun 10 at 6:12
@YashShah check updated question
– Waqar Ali
Jun 10 at 6:19
You can code like this. $options[2]['value'] = $cms->toArray();
– Yash Shah
Jun 10 at 6:25
on toArray() getting errorFatal error: Uncaught Error: Call to a member function toArray() on array
– Waqar Ali
Jun 10 at 6:29
1
In that case, $options[2]['value'] = $cms; should work.
– Yash Shah
Jun 10 at 6:39
I think both are same. I dont get any difference between what you get and what you want ..
– Yash Shah
Jun 10 at 6:12
I think both are same. I dont get any difference between what you get and what you want ..
– Yash Shah
Jun 10 at 6:12
@YashShah check updated question
– Waqar Ali
Jun 10 at 6:19
@YashShah check updated question
– Waqar Ali
Jun 10 at 6:19
You can code like this. $options[2]['value'] = $cms->toArray();
– Yash Shah
Jun 10 at 6:25
You can code like this. $options[2]['value'] = $cms->toArray();
– Yash Shah
Jun 10 at 6:25
on toArray() getting error
Fatal error: Uncaught Error: Call to a member function toArray() on array
– Waqar Ali
Jun 10 at 6:29
on toArray() getting error
Fatal error: Uncaught Error: Call to a member function toArray() on array
– Waqar Ali
Jun 10 at 6:29
1
1
In that case, $options[2]['value'] = $cms; should work.
– Yash Shah
Jun 10 at 6:39
In that case, $options[2]['value'] = $cms; should work.
– Yash Shah
Jun 10 at 6:39
|
show 3 more comments
2 Answers
2
active
oldest
votes
Why not?
$cms = $this->collectionFactory->create()->toOptionArray();
$options = [
// your code
[
'label' => __('CMS pages'),
'value' => $cms
]
];
that worked for me thank you
– Waqar Ali
Jun 10 at 7:17
add a comment |
Try Foreach loop will help.
Syntex :
$data = $cms->toArray();
foreach ($variable as $key => $value)
let me know if anything you need.
Thanks
strill getting same result
– Waqar Ali
Jun 10 at 6:09
try once $collection->toArray();
– Adarsh Shukla
Jun 10 at 6:13
i tried this gettingFatal error: Uncaught Error: Call to a member function toArray() on array
– Waqar Ali
Jun 10 at 6:21
have you eddited question?
– Adarsh Shukla
Jun 10 at 6:22
yes i just added code where i want to add these options
– Waqar Ali
Jun 10 at 6:23
|
show 3 more comments
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%2f277760%2fhow-to-convert-an-object-into-array-in-magento-2%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
Why not?
$cms = $this->collectionFactory->create()->toOptionArray();
$options = [
// your code
[
'label' => __('CMS pages'),
'value' => $cms
]
];
that worked for me thank you
– Waqar Ali
Jun 10 at 7:17
add a comment |
Why not?
$cms = $this->collectionFactory->create()->toOptionArray();
$options = [
// your code
[
'label' => __('CMS pages'),
'value' => $cms
]
];
that worked for me thank you
– Waqar Ali
Jun 10 at 7:17
add a comment |
Why not?
$cms = $this->collectionFactory->create()->toOptionArray();
$options = [
// your code
[
'label' => __('CMS pages'),
'value' => $cms
]
];
Why not?
$cms = $this->collectionFactory->create()->toOptionArray();
$options = [
// your code
[
'label' => __('CMS pages'),
'value' => $cms
]
];
answered Jun 10 at 7:11
tokeytokey
862
862
that worked for me thank you
– Waqar Ali
Jun 10 at 7:17
add a comment |
that worked for me thank you
– Waqar Ali
Jun 10 at 7:17
that worked for me thank you
– Waqar Ali
Jun 10 at 7:17
that worked for me thank you
– Waqar Ali
Jun 10 at 7:17
add a comment |
Try Foreach loop will help.
Syntex :
$data = $cms->toArray();
foreach ($variable as $key => $value)
let me know if anything you need.
Thanks
strill getting same result
– Waqar Ali
Jun 10 at 6:09
try once $collection->toArray();
– Adarsh Shukla
Jun 10 at 6:13
i tried this gettingFatal error: Uncaught Error: Call to a member function toArray() on array
– Waqar Ali
Jun 10 at 6:21
have you eddited question?
– Adarsh Shukla
Jun 10 at 6:22
yes i just added code where i want to add these options
– Waqar Ali
Jun 10 at 6:23
|
show 3 more comments
Try Foreach loop will help.
Syntex :
$data = $cms->toArray();
foreach ($variable as $key => $value)
let me know if anything you need.
Thanks
strill getting same result
– Waqar Ali
Jun 10 at 6:09
try once $collection->toArray();
– Adarsh Shukla
Jun 10 at 6:13
i tried this gettingFatal error: Uncaught Error: Call to a member function toArray() on array
– Waqar Ali
Jun 10 at 6:21
have you eddited question?
– Adarsh Shukla
Jun 10 at 6:22
yes i just added code where i want to add these options
– Waqar Ali
Jun 10 at 6:23
|
show 3 more comments
Try Foreach loop will help.
Syntex :
$data = $cms->toArray();
foreach ($variable as $key => $value)
let me know if anything you need.
Thanks
Try Foreach loop will help.
Syntex :
$data = $cms->toArray();
foreach ($variable as $key => $value)
let me know if anything you need.
Thanks
edited Jun 10 at 6:33
Rk Rathod
2,314315
2,314315
answered Jun 10 at 6:07
Adarsh ShuklaAdarsh Shukla
34714
34714
strill getting same result
– Waqar Ali
Jun 10 at 6:09
try once $collection->toArray();
– Adarsh Shukla
Jun 10 at 6:13
i tried this gettingFatal error: Uncaught Error: Call to a member function toArray() on array
– Waqar Ali
Jun 10 at 6:21
have you eddited question?
– Adarsh Shukla
Jun 10 at 6:22
yes i just added code where i want to add these options
– Waqar Ali
Jun 10 at 6:23
|
show 3 more comments
strill getting same result
– Waqar Ali
Jun 10 at 6:09
try once $collection->toArray();
– Adarsh Shukla
Jun 10 at 6:13
i tried this gettingFatal error: Uncaught Error: Call to a member function toArray() on array
– Waqar Ali
Jun 10 at 6:21
have you eddited question?
– Adarsh Shukla
Jun 10 at 6:22
yes i just added code where i want to add these options
– Waqar Ali
Jun 10 at 6:23
strill getting same result
– Waqar Ali
Jun 10 at 6:09
strill getting same result
– Waqar Ali
Jun 10 at 6:09
try once $collection->toArray();
– Adarsh Shukla
Jun 10 at 6:13
try once $collection->toArray();
– Adarsh Shukla
Jun 10 at 6:13
i tried this getting
Fatal error: Uncaught Error: Call to a member function toArray() on array
– Waqar Ali
Jun 10 at 6:21
i tried this getting
Fatal error: Uncaught Error: Call to a member function toArray() on array
– Waqar Ali
Jun 10 at 6:21
have you eddited question?
– Adarsh Shukla
Jun 10 at 6:22
have you eddited question?
– Adarsh Shukla
Jun 10 at 6:22
yes i just added code where i want to add these options
– Waqar Ali
Jun 10 at 6:23
yes i just added code where i want to add these options
– Waqar Ali
Jun 10 at 6:23
|
show 3 more comments
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%2f277760%2fhow-to-convert-an-object-into-array-in-magento-2%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
I think both are same. I dont get any difference between what you get and what you want ..
– Yash Shah
Jun 10 at 6:12
@YashShah check updated question
– Waqar Ali
Jun 10 at 6:19
You can code like this. $options[2]['value'] = $cms->toArray();
– Yash Shah
Jun 10 at 6:25
on toArray() getting error
Fatal error: Uncaught Error: Call to a member function toArray() on array
– Waqar Ali
Jun 10 at 6:29
1
In that case, $options[2]['value'] = $cms; should work.
– Yash Shah
Jun 10 at 6:39