Skip to content

Instantly share code, notes, and snippets.

@wisaruthk
Created November 16, 2015 08:39
Show Gist options
  • Save wisaruthk/7c2446bd7849f57e68d5 to your computer and use it in GitHub Desktop.
Save wisaruthk/7c2446bd7849f57e68d5 to your computer and use it in GitHub Desktop.
ตัวอย่าง กำหนด response เป็น json สำหรับ controller ที่ระบุ
public function behaviors() {
$behaviors = parent::behaviors();
$behaviors['authenticator'] = [
'class' => \yii\filters\auth\HttpBasicAuth::className(),
'only' => ['hi','token-log-in', 'log-out',
'list-template-data',
'download-template-data'],
];
$behaviors['response'] = [
'class' => 'yii\filters\ContentNegotiator',
'formats' => [
'application/json' => Response::FORMAT_JSON,
],
];
//$behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON;
return $behaviors;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment