Reading list Switch to dark mode

    parse_str() alternative in magento 2

    Updated 7 August 2019

    As we know that magento restrict some core PHP functions which we found in MEQP2 which contains the rules.

    Let’s start to over come this issue.

    As we know Magento 2 is using Zend Framework ther is a class \Zend\Uri\Uri

    First initialise Zend Uri in your class constructor.

    public function __construct(
            \Zend\Uri\Uri $zendUri
        ) {
            $this->zendUri = $zendUri;
        }

    Now set the query string and then get it as array.

    Start your headless eCommerce
    now.
    Find out More
    $data = $this->getRequest()->getParams();
    $this->zendUri->setQuery($data);
    $formatedParams = $this->zendUri->getQueryAsArray();
    // $formatedParams is an array of query string.

    $formatedParams contains an array of your querystring.

    print_r($formatedParams)
    // Output
    
    Array
    (
        [product] => Array
            (
                [1] => Array
                    (
                        [name] => Customization
                        [price] => 100
                    )
    
            )
    
    )

    . . .

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    Be the first to comment.

    Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home