【发布时间】:2022-06-21 15:08:29
【问题描述】:
在我的颤振应用程序中,我有两个页面来显示和添加/编辑一些数据。我正在使用提供者和消费者构造器,但是当我添加或编辑数据并导航回显示我的数据的页面时,它们没有被更新。
Provider 函数正在运行以获取数据,但我猜 php 端有一些问题。 当 get 请求首先到达 php 文件时,它会检查密钥。
if (array_key_exists("parentid", $_GET)&&array_key_exists("moduleid", $_GET))
然后我像这样分开请求方法:
if($_SERVER['REQUEST_METHOD'] === 'GET') {..}
if($_SERVER['REQUEST_METHOD'] === 'DELETE') {..}
这是完整的代码:
if (array_key_exists("parentid", $_GET)&&array_key_exists("moduleid", $_GET)) {
error_log("This condition work fine");
$parentid = $_GET['parentid'];
$moduleid = $_GET['moduleid'];
if($parentid == '' || !is_numeric($parentid)) {
$response = new Response();
$response->setHttpStatusCode(400);
$response->setSuccess(false);
$response->addMessage("Parent ID cannot be blanck or must be numeric");
$response->send();
exit;
}
if($moduleid == '' || !is_numeric($moduleid)) {
$response = new Response();
$response->setHttpStatusCode(400);
$response->setSuccess(false);
$response->addMessage("Module ID cannot be blanck or must be numeric");
$response->send();
exit;
}
if($_GET) {
error_log("here we stack");
try {
$querySetNames = $readDB->prepare("SET NAMES 'utf8'");
$querySetNames->execute();
$query = $readDB->prepare('SELECT ... }
if($_SERVER['REQUEST_METHOD'] === 'DELETE') {..}
if($_SERVER['REQUEST_METHOD'] === 'PATCH') {..}
}
我尝试使用
if($_SERVER['REQUEST_METHOD'] == 'GET') {..}
和
if($_SERVER['REQUEST_METHOD'] === 'GET') {..}
而不是
if($_GET)
。但它没有用。
因此,我无法获得更新的数据。可能是什么原因?