Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Zend framework2 ZF2-如何在模型内设置cookie?_Zend Framework2 - Fatal编程技术网

Zend framework2 ZF2-如何在模型内设置cookie?

Zend framework2 ZF2-如何在模型内设置cookie?,zend-framework2,Zend Framework2,我尝试在模型中设置cookie,但它似乎不起作用。有什么想法吗 $header = new \Zend\Http\Header\SetCookie(); $header->setName('Token'); $header->setValue($token); $header->setPath('/'); $header->setDomain('localhost'); $header->setExpires(time()+(3600*24*365)); $cli

我尝试在模型中设置cookie,但它似乎不起作用。有什么想法吗

$header = new \Zend\Http\Header\SetCookie();
$header->setName('Token');
$header->setValue($token);
$header->setPath('/');
$header->setDomain('localhost');
$header->setExpires(time()+(3600*24*365));

$client = new \Zend\Http\Client();
$client->addCookie($header);

您需要将头添加到HTTP响应对象,而不是HTTP客户端的随机实例

不过,该模型可能并不适合这种情况。根据您正试图执行的操作,我建议您返回令牌,以便您可以在控制器操作中设置此cookie