LoginSignup
2
1

More than 5 years have passed since last update.

ZendFramework1 で setcookie する

Posted at

ZF1 で Set-Cookie ヘッダを吐きたかったんですが、ググると Zend_Http_Cookie ばっかり引っかかります。
Zend_Http_CookieZend_Http_Client で利用するもので、フロントコントローラでの利用は想定されていません(多分)。

さらにググると、ネイティブの setcookie 関数を使用している例も結構見つかります。
「まさかできないわけないだろー」と調べた所、無事Zend_Http_Header_SetCookie クラスを発見出来ました。
このクラスを使用するとクッキーの属性などをオブジェクティブに扱えるので便利です。

…が、実は公式ドキュメントに書いてあったりします。
レスポンスオブジェクト - Zend_Controller - Zend Framework

上記から引用:

$cookie = new Zend_Http_Header_SetCookie();
$cookie->setName('foo')
       ->setValue('bar')
       ->setDomain('example.com')
       ->setPath('/')
       ->setHttponly(true);
$this->getResponse()->setRawHeader($cookie);

Zend_Http_Header_SetCookie でググっても 49 件しかヒットしないんだぜ?
結構ありそうな処理なのになぜ…。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1