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
Aasim Goriya
5,4622 gold badges30 silver badges54 bronze badges
2 Answers 2
Why not?
$cms = $this->collectionFactory->create()->toOptionArray();
$options = [
// your code
[
'label' => __('CMS pages'),
'value' => $cms
]
];
Try Foreach loop will help.
Syntex :
$data = $cms->toArray();
foreach ($variable as $key => $value)
{
}
let me know if anything you need.
Thanks
Ronak Rathod
6,58020 silver badges46 bronze badges
answered Jun 10, 2019 at 6:07
Adarsh Shukla
5831 gold badge7 silver badges26 bronze badges
-
strill getting same resultWaqar Ali– Waqar Ali2019年06月10日 06:09:58 +00:00Commented Jun 10, 2019 at 6:09
-
try once $collection->toArray();Adarsh Shukla– Adarsh Shukla2019年06月10日 06:13:48 +00:00Commented Jun 10, 2019 at 6:13
-
i tried this getting
Fatal error: Uncaught Error: Call to a member function toArray() on arrayWaqar Ali– Waqar Ali2019年06月10日 06:21:21 +00:00Commented Jun 10, 2019 at 6:21 -
have you eddited question?Adarsh Shukla– Adarsh Shukla2019年06月10日 06:22:42 +00:00Commented Jun 10, 2019 at 6:22
-
yes i just added code where i want to add these optionsWaqar Ali– Waqar Ali2019年06月10日 06:23:25 +00:00Commented Jun 10, 2019 at 6:23
default
Fatal error: Uncaught Error: Call to a member function toArray() on array