question about cookies

dont underststand what matter:

class CartController extends Controller


public function actionEnterdata2()


  // block 1 begin

   $cookies6 = Yii::$app->request->cookies; 

   $language = $cookies6->getValue('language', 'en');

   echo "----"; echo $language; echo "----";

 // block 1 end

 // block 2 begin

   $cookies5 = Yii::$app->response->cookies;

   $cookies5->add(new \yii\web\Cookie([

      'name' => 'language',

      'value' => 'engeng',


 //block 2 end

return $this->render (enterdata) ;




i cant set cookie. string: echo "----"; echo $language; echo "----"; show me previously set value no matter how many times i reload page. But when i delete block1 , then reload, then return back block1, then reload - all right. i see wanted value. Why so?

by testing i was understand, that if i delete "echo" in action of controller and see result by render view, then all good.