{"id":4954,"date":"2021-08-09T07:40:30","date_gmt":"2021-08-09T07:40:30","guid":{"rendered":"https:\/\/www.bearloga.space\/?page_id=4954"},"modified":"2021-08-09T07:40:30","modified_gmt":"2021-08-09T07:40:30","slug":"yii-http-zaprosy","status":"publish","type":"page","link":"https:\/\/www.bearloga.space\/en\/yii-http-zaprosy\/","title":{"rendered":"Yii \u2014 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u044b"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u0417\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c&nbsp;<strong>yii \\ web \\ Request<\/strong>&nbsp;, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430\u0445 HTTP, \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0444\u0430\u0439\u043b\u0430\u0445 cookie \u0438 \u0442. \u0414.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u041c\u0435\u0442\u043e\u0434\u044b&nbsp;<strong>get ()<\/strong>&nbsp;\u0438&nbsp;<strong>post ()<\/strong>&nbsp;\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u041f\u0440\u0438\u043c\u0435\u0440<\/strong>&nbsp;\u2014<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$req = Yii::$app-&gt;request;\n   \/*\n   * $get = $_GET;\n   *\/\n   $get = $req-&gt;get();\n\n   \/*\n   * if(isset($_GET['id'])) {\n   *     $id = $_GET['id'];\n   * } else {\n   *     $id = null;\n   * }\n   *\/\n   $id = $req-&gt;get('id');\n\t\n   \/*\n   * if(isset($_GET['id'])) {\n   *     $id = $_GET['id'];\n   * } else {\n   *     $id = 1;\n   * }\n   *\/\n   $id = $req-&gt;get('id', 1);\n\t\n   \/*\n   * $post = $_POST;\n\t*\/\n   $post = $req-&gt;post();\n\n   \/*\n   * if(isset($_POST['name'])) {       \n   *     $name = $_POST['name'];          \n   * } else {\n   *     $name = null;\n   * }\n   *\/\n   $name = $req-&gt;post('name');\n\t\t  \n   \/*\n   * if(isset($_POST['name'])) {\n   *     $name = $_POST['name'];\n   * } else {\n   *     $name = '';\n   * }\n   *\/\n   $name = $req-&gt;post('name', '');<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u0428\u0430\u0433 1<\/strong>&nbsp;\u2014 \u0414\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e&nbsp;<strong>actionTestGet<\/strong>&nbsp;\u0432&nbsp;<strong>SiteController<\/strong>&nbsp;\u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">public function actionTestGet() {\n   var_dump(Yii::$app-&gt;request-&gt;get());\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u0428\u0430\u0433 2<\/strong>&nbsp;\u2014 \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0439\u0434\u0438\u0442\u0435 \u043f\u043e&nbsp;<strong>\u0430\u0434\u0440\u0435\u0441\u0443 http: \/\/ localhost: 8080 \/ index.php? R = site \/ testget &amp; id = 1 &amp; name = tutorialspoint &amp; message = welcome<\/strong>&nbsp;, \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/coderlessons.com\/wp-content\/uploads\/2019\/07\/actiontestget_function_output.png\" alt=\"\u0412\u044b\u0445\u043e\u0434 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 actionTestGet\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u0440\u0443\u0433\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 (PATCH, DELETE \u0438 \u0442. \u0414.), \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043c\u0435\u0442\u043e\u0434&nbsp;<strong>yii \\ web \\ Request :: getBodyParam ()<\/strong>&nbsp;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043c\u0435\u0442\u043e\u0434 HTTP \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e&nbsp;<strong>Yii :: $ app \u2192 request \u2192 method<\/strong>&nbsp;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u0428\u0430\u0433 3<\/strong>\u00a0\u2014 \u0418\u0437\u043c\u0435\u043d\u0438\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e\u00a0<strong>actionTestGet,<\/strong>\u00a0\u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043a\u043e\u0434\u0435.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">public function actionTestGet() {\n   $req = Yii::$app-&gt;request;\n   if ($req-&gt;isAjax) {\n      echo \"the request is AJAX\";\n   }\n   if ($req-&gt;isGet) {\n      echo \"the request is GET\";\n   }\n   if ($req-&gt;isPost) {\n      echo \"the request is POST\";\n   }\n   if ($req-&gt;isPut) {\n      echo \"the request is PUT\";\n   }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u0428\u0430\u0433 4<\/strong>&nbsp;\u2014 \u041f\u0435\u0440\u0435\u0439\u0434\u0438\u0442\u0435 \u043d\u0430&nbsp;<strong>http: \/\/ localhost: 8080 \/ index.php? R = site \/ test-get<\/strong>&nbsp;.&nbsp;\u0412\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/coderlessons.com\/wp-content\/uploads\/2019\/07\/get_request.png\" alt=\"\u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0437\u0430\u043f\u0440\u043e\u0448\u0435\u043d\u043d\u043e\u0433\u043e URL.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u0428\u0430\u0433 5<\/strong>&nbsp;\u2014 \u0418\u0437\u043c\u0435\u043d\u0438\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e&nbsp;<strong>actionTestGet<\/strong>&nbsp;\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">public function actionTestGet() {\n   \/\/the URL without the host\n   var_dump(Yii::$app-&gt;request-&gt;url);\n   \n   \/\/the whole URL including the host path\n   var_dump(Yii::$app-&gt;request-&gt;absoluteUrl);\n   \n   \/\/the host of the URL\n   var_dump(Yii::$app-&gt;request-&gt;hostInfo);\n   \n   \/\/the part after the entry script and before the question mark\n   var_dump(Yii::$app-&gt;request-&gt;pathInfo);\n   \n   \/\/the part after the question mark\n   var_dump(Yii::$app-&gt;request-&gt;queryString);\n   \n   \/\/the part after the host and before the entry script\n   var_dump(Yii::$app-&gt;request-&gt;baseUrl);\n   \n   \/\/the URL without path info and query string\n   var_dump(Yii::$app-&gt;request-&gt;scriptUrl);\n   \n   \/\/the host name in the URL\n   var_dump(Yii::$app-&gt;request-&gt;serverName);\n   \n   \/\/the port used by the web server\n   var_dump(Yii::$app-&gt;request-&gt;serverPort);\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u0428\u0430\u0433 6<\/strong>&nbsp;\u2014 \u0412 \u0430\u0434\u0440\u0435\u0441\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u0435\u0431-\u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430 \u0432\u0432\u0435\u0434\u0438\u0442\u0435&nbsp;<strong>http: \/\/ localhost: 8080 \/ index.php? R = site \/ testget &amp; id = 1 &amp; name = tutorialspoint &amp; message = welcome<\/strong>&nbsp;, \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/coderlessons.com\/wp-content\/uploads\/2019\/07\/modify_actiontestget_function_output.png\" alt=\"\u0418\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 Actiontestget\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u0428\u0430\u0433 7<\/strong>&nbsp;\u2014 \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 HTTP, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e&nbsp;<strong>yii \\ web \\ Request :: $ headers<\/strong>&nbsp;.&nbsp;\u041c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0439\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e&nbsp;<strong>actionTestGet<\/strong>&nbsp;\u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">public function actionTestGet() { \n   var_dump(Yii::$app-&gt;request-&gt;headers); \n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u0428\u0430\u0433 8.<\/strong>&nbsp;\u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u0442\u0435 \u043f\u043e URL-\u0430\u0434\u0440\u0435\u0441\u0443&nbsp;<strong>http: \/\/ localhost: 8080 \/ index.php? R = site \/ testget &amp; id = 1 &amp; name = tutorialspoint &amp; message = welcome<\/strong>&nbsp;, \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u0432\u044b\u0432\u043e\u0434, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043a\u043e\u0434\u0435.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/coderlessons.com\/wp-content\/uploads\/2019\/07\/modified_actiontestget_function_output.png\" alt=\"\u041c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 Actiontestget\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043c\u044f \u0445\u043e\u0441\u0442\u0430 \u0438 IP-\u0430\u0434\u0440\u0435\u0441 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430&nbsp;<strong>userHost<\/strong>&nbsp;\u0438&nbsp;<strong>userIP<\/strong>&nbsp;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u0428\u0430\u0433 9<\/strong>&nbsp;\u2014 \u041c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0439\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e&nbsp;<strong>actionTestGet<\/strong>&nbsp;\u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">public function actionTestGet() {\n   var_dump(Yii::$app-&gt;request-&gt;userHost);\n   var_dump(Yii::$app-&gt;request-&gt;userIP);\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u0428\u0430\u0433 10<\/strong>&nbsp;\u2014 \u041f\u0435\u0440\u0435\u0439\u0434\u0438\u0442\u0435 \u043f\u043e \u0430\u0434\u0440\u0435\u0441\u0443&nbsp;<strong>http: \/\/ localhost: 8080 \/ index.php? R = site \/ test-get<\/strong>&nbsp;\u0438 \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u044d\u043a\u0440\u0430\u043d.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0417\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c&nbsp;yii \\ web \\ Request&nbsp;, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430\u0445 HTTP, \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u0444\u0430\u0439\u043b\u0430\u0445 cookie \u0438 \u0442. \u0414. [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[156],"tags":[],"class_list":["post-4954","page","type-page","status-publish","hentry","category-yii"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/pages\/4954","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/comments?post=4954"}],"version-history":[{"count":1,"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/pages\/4954\/revisions"}],"predecessor-version":[{"id":4955,"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/pages\/4954\/revisions\/4955"}],"wp:attachment":[{"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/media?parent=4954"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/categories?post=4954"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/tags?post=4954"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}