Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii framework 1.1 get the http request Header in Controller action

Tags:

php

curl

yii

The API url is www.example.com/api/users?name=test

the curl command curl -H "Connection:keep-alive \n User-Agent: Mozilla/5.0 \n Accept:application/json" http://www.example.com/api/users?name=test

in the API controller user action, how to get the header information

public function actionUsers()  
    {  
       $this->_checkAuth();  

        // Get Accept type info ???
}
like image 854
AntiGMO Avatar asked Feb 19 '26 05:02

AntiGMO


1 Answers

Use CHttpRequest::acceptTypes which:

Returns user browser accept types, null if not present.

CHttpRequest is a default component and can be accessed via Yii::app()->request:

public function actionUsers()  
{  
    $this->_checkAuth();
    $types = Yii::app()->request->acceptTypes;
}
like image 68
topher Avatar answered Feb 21 '26 17:02

topher