gpt4 book ai didi

php - 我怎样才能访问 POST 数据,然后在 CakePHP 中将其删除?

转载 作者:行者123 更新时间:2023-11-29 00:31:17 26 4
gpt4 key购买 nike

我正在构建一个连接到我的远程服务器的 Android 应用程序。我允许用户添加新内容,但在允许添加之前还必须对他们进行身份验证。这是他们添加的示例:

List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair(SharedVariables.TAG_NAME, name));
params.add(new BasicNameValuePair(SharedVariables.TAG_ADDRESS, address));
params.add(new BasicNameValuePair(SharedVariables.TAG_TYPE, type));
params.add(new BasicNameValuePair(SharedVariables.TAG_DESCRIPTION, description));
params.add(new BasicNameValuePair(SharedVariables.TAG_DIFFICULTY, difficulty));
params.add(new BasicNameValuePair(SharedVariables.TAG_TERRAIN, terrain));
params.add(new BasicNameValuePair(SharedVariables.TAG_LONG, Double.toString(currentLng)));
params.add(new BasicNameValuePair(SharedVariables.TAG_LAT, Double.toString(currentLat)));
params.add(new BasicNameValuePair(SharedVariables.TAG_UID, Integer.toString(2)));

//Retrieve hash and id to identify authenticate user
UserAuth auth = new UserAuth(AddSpot.this);
HashMap<String,String> session = auth.getUserDetails();
params.add(new BasicNameValuePair(SharedVariables.TAG_UID, session.get("id")));
params.add(new BasicNameValuePair(SharedVariables.TAG_HASH, session.get("hash")));

如您所见,在第一部分中,我存储了用户自己添加的内容,但是,我还传递了用户 ID,然后将 token /哈希传递到 POST 数据中,如在最后部分。我的问题是,我不想使用 $this->Location->save($this->request->data) 将所有内容添加到数据库表中。相反,我希望能够挑选出用户 ID 和哈希并将其删除,然后保存所有其他内容。我如何在 CakePHP 中执行此操作?

这是我现在在 CakePHP 中的方法:

function add()
{
if ($this->request->is('post'))
{
$response = array();
$this->loadModel('User');
if($this->User->validateHash($id, $hash))
{
//Do some logic to remove id and hash from request

$this->Location->create();
//Save data from POST
if ($this->Location->save($this->request->data))
{
//Successfully saved
$this->response->statusCode(200);
}
else
{
//Error in saving
$this->response->statusCode(500);
}
}
else
{
//Does their hash match? No, then they are unauthorized to add
$this->response->statusCode(401);
}
}
$this->set(compact('response'));
$this->set('_serialize', array('response'));
}

最佳答案

这个?

unset($this->request->data['YourModel']['id']);
unset($this->request->data['YourModel']['hash']);

关于php - 我怎样才能访问 POST 数据,然后在 CakePHP 中将其删除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15590406/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com