setcookie not working

Hi,

I’m using Yii2 Advanced template and I want to set a cookie in frontend, but it is not working with php function setcookie

Not working:

            setcookie('popup','closed',time()+30,'/');

Working:

Yii::$app->response->cookies->add(new \yii\web\Cookie([‘name’ => ‘popup’,

                        'value' => 'closed',


                        'expire'=>time()+30,


                        'path'=>'/'


                    ]));

But I need to only set cookie with php function, how is it possible?

Thanks

Why can’t you use Yii method?