AI写作智能体 自主规划任务,支持联网查询和网页读取,多模态高效创作各类分析报告、商业计划、营销方案、教学内容等。 广告
## 操作header一般不多用,但用起来也挺简单 ~~~php public function actionTest(){ $headers = Yii::$app->response->headers; //添加,如果已存在则不会覆盖 $headers->add('xx', 'yy'); if($headers->has('xx')){ $headers->add('aa', 'bb'); $headers->add('cc', 'dd'); } //设置,会覆盖原有的 $headers->set('xx', 'zz'); //$headers['xx'] = 'zz'; //等效,可以用数组赋值取值方式来操作,也能isset,unset //添加,如果已存在则不会覆盖 $headers->add('xx', 'yy'); //已存在,还是zz //删除 $headers->remove('cc'); print_r([count($headers), $headers->toArray()]); } ~~~ add、set、get和remove就不废话了,其实也还有removeAll 其中比较好的就是它不是马上发送的,而是控制器返回到底层后,由底层调用response组件统一发送的,详见[yii\\web\\Response](http://www.yiichina.com/doc/api/2.0/yii-web-response)的`sendHeaders`方法