Menu Close
    Hire Us Request Quote Reading List Switch to Dark Mode

    parse_str() alternative in magento 2

    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.

    $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
                    )
    
            )
    
    )
    . . .

    Comment

    Add Your Comment

    Be the first to comment.

    Back to Top
    css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again
    Close