file_get_contents("php://input")
或者$HTTP_RAW_POST_DATA
- 哪一个更好地获得JSON请求的主体?
在使用客户端时,我应该使用哪种请求类型(GET
或POST
)来发送JSON数据XmlHTTPRequest
?
我的问题来自这个答案: 如何使用curl将JSON发布到PHP
从那个回答引用:
从协议的角度来看
file_get_contents("php://input")
实际上更正确,因为你还没有真正处理http多部分表单数据.
有2个需要的功能:注册时设置密码和更改密码,如果用户忘记了.用户注册时,密码长度必须至少为4个字符; 当变化通过时 - 至少5个字符.
视图通常用于注册和更改传递.显然,还存在2个动作,其中任一个场景'注册',或者使用'改变'.模型中的代码段:
public function rules() {
return [
['password', 'string', 'min' => 4, 'on' => 'signup'],
['password', 'string', 'min' => 5, 'on' => 'change'],
];
}
Run Code Online (Sandbox Code Playgroud)
但我想通过scenario()做到这一点.怎么做?我是Yii的初学者,所以不明白,何时以及如何使用scenario().谢谢.
UPD.我需要使用场景()用于ONE场ONE规则,但是不同参数这一规律.如何在Yii2中定义场景? - 这不是我的情况.
我只能修改ajax中的代码调用当我单击名为$('#form1')的表单中的提交时发出的ajax调用
$('#form1').submit(function () {
$.ajax({
url: 'some.php',
type: 'POST',
data: somedata,
success: function (msg) {
if (!msg) {
// I wanna to stop '#form1' submit here,how to do that? I can only modify the code in the ajax call.
}
}
});
});
Run Code Online (Sandbox Code Playgroud) 我仍然是任何API的初学者,所以需要帮助.据我了解,服务"网站管理员"在谷歌的API的PHP客户端库允许我收到这样的数据CTR
,Clicks
等等.
我从github下载了lib文件并将其打入localhost.然后在谷歌开发者控制台中我创建了项目(真的不明白,为什么?这个项目不包含任何关于网站的信息,我需要哪些搜索信息).而对于项目创建服务器密钥后(通过"添加凭据"在谷歌开发者控制台,而无需输入任何IP它).Google Search Console API已启用.我是我网站的完全用户(我可以在Google Search Console中看到它).我也有谷歌帐户,当然,并登录.
我在lib的examples文件夹中创建的源文件,以及其他示例:
include_once "templates/base.php";
require_once realpath(dirname(__FILE__) . '/../src/Google/autoload.php');
$client = new Google_Client();
$client->setApplicationName("Client_Library_Examples");
$apiKey = "AIzaSyCOJ56353XByxh8rCpfgfhgfhZzopSLUe"; // Value of server key, that I created in for my project ().
if (strpos($apiKey, "<") !== false) {
echo missingApiKeyWarning();
exit;
}
$client->setDeveloperKey($apiKey);
//here are my efforts
$service = new Google_Service_Webmasters($client);
var_dump($service->searchanalytics->query(
'http://sschesnok.com.ua',
new Google_Service_Webmasters_SearchAnalyticsQueryRequest())); //I'm not sure about …
Run Code Online (Sandbox Code Playgroud)