1. Return 404

The YII framework uses the Response class to modify statusCode as follows

$res = \Yii::$app->response;
$res->statusCode = '404';
Copy the code

2. Add configuration information to the response header

Use the add method in the header class to disable the browser cache configuration.

$res = \Yii::$app->response;
$res->headers->add('pragma'.'no-cache');
Copy the code

3. Modify the response header

Use the set method to modify

$res->headers->set('pragma'.'max-age=5');
Copy the code

4. Delete the response header configuration

$res->headers->remove('pragma');
Copy the code

5, jump

$this->redirect('http://www.baidu.com', 302);Copy the code

302 indicates a temporary redirect to Baidu.com

6. File download

$res->headers->add('content-disposition'.'attachment; filename="a.jpg"');
Copy the code

You can also use the default method

$res->sendFile('./b.png');
Copy the code

Note that the default path is in the same directory as /web/index.php.