AntiGMO
AntiGMO

Reputation: 1587

Yii framework 1.1 get the http request Header in Controller action

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 ???
}

Upvotes: 3

Views: 4118

Answers (1)

topher
topher

Reputation: 14860

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;
}

Upvotes: 2

Related Questions