Jump to content

The use of function header() is forbidden


Recommended Posts

Hello,

In my module i use next code

header('Content-Type: application/json');

Received the following comment from prestashop team

The use of function header() is forbidden; use Tools::redirect() or Tools::redirectLink() instead header('Content-Type: application/json');

Tell me how to properly replace this line on Tools::redirect()

Thank you in advance

 

Link to comment
Share on other sites

Yes, of course this line used for module "Compare"

This used for action add, remove or remove all products
Example of use function with "header'

 

 public function processRemoveAll()
    {
        header('Content-Type: application/json');

        $productsIds = array();
        $productsIds = Tools::jsonEncode($productsIds, true);
        $this->context->cookie->__set('brilliantCompare', $productsIds);
        
        $this->ajaxDie(Tools::jsonEncode(array(
            'success' => true,
            'data' => [
                'message' => $this->module->l('All products removed','actions'),
                'type' => 'removedAll',
                'view' => $this->module->l('View compare','actions')
            ]
        )));
    }

 

 

Link to comment
Share on other sites

On 18.09.2018 at 8:39 PM, Rolige said:

Ok, you need call it from an external call, not inside the module,  or by ajax.

Sorry, but I'm a novice developer, could you please explain in more detail what needs to be done.

Thank you in advance

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...