如何在slim框架中同时读取Json和File?我正在尝试这个:
$entityManager = $this -> get(‘em’);
try{
//Salvar foto
$files = $request->getUploadedFiles();
$newimage = $files['foto'];
if ($newimage->getError() === UPLOAD_ERR_OK) {
$uploadFileName = $newimage->getClientFilename();
$type = $newimage->getClientMediaType();
$name = uniqid('img-' . date('d-m-y') . '-');
$name .= $newimage->getClientFilename();
// $imgs[] = array('url' => '/Photos/' . $name);
//local server
$newimage->moveTo("/home/citycare/imgs/$name");#/home/citycare/Imgs/User/$name
//localdev
$photoURL = "/home/citycare/public_html/Imgs/user/$name";#/home/citycare/Imgs/User/$name
}
//Instância da entidade Login
$login = new Login();
//recuperando o parâmetro objeto login do json
$fk_login_cidadao = $request->getParam('fk_login_cidadao');
//setando valores do objeto login
$login ->setLogin($fk_login_cidadao['login']);
$login ->setEmail($fk_login_cidadao['email']);
$login ->setSenha($fk_login_cidadao['senha']);
$login ->setStatus_login($fk_login_cidadao['status_login']);
$login ->setAsAdministrador($fk_login_cidadao['administrador']);
//salvando login
$entityManager->persist($login);
$entityManager->flush();
//buscando login recém salvo
$loginRepository = $entityManager->getRepository('App\Models\Entity\Login');
//pegando login
$loginCidadao = $loginRepository->find($login->getId_login());
//Instância da entidade Cidadao
$cidadao = new Cidadao();
//setando valores do objeto cidadao
$cidadao ->setFk_login_cidadao($loginCidadao);
$cidadao->setNome($request->getParam('nome'));
$cidadao->setSexo($request->getParam('sexo'));
$cidadao ->setSobrenome($request->getParam('sobrenome'));
$cidadao ->setEstado($request->getParam('estado'));
$cidadao ->setCidade($request->getParam('cidade'));
$cidadao ->setDir_foto_usuario($request->getParam($photoURL));
$entityManager->persist($cidadao);
$entityManager->flush();
//retornando confirmação do evento completo
$return = $response->withJson(["result" => true],201)->withHeader('Content-type', 'application/json');
} catch (Exception $ex){
//código e mensagem do erro
throw new Exception($ex->getMessage(), $ex->getCode());
}
return $return;
}
but I’m getting this {“message”:"An exception occurred while executing ‘INSERT INTO login (email, login, senha, status_login, administrador) VALUES (?, ?, ?, ?, ?)’ with params [null, null, “”, null, null]:\n\nSQLSTATE[23000]:
我正在从Android应用程序中收到Json和File,现在我正在尝试使用内容类型的json帖子;
内容 - 处置:表单数据;名称= “cidadao”
这是json:
内容类型:multipart / form-data;字符集= utf-8的 { “CIDADE”: “艾瓦巴”, “国家体制”: “塞阿拉州”, “fk_login_cidadao”:{ “administrador”:假的, “电子邮件”: “jvictor@jvictor.com”, “登陆”: “kikokiko”,“senha “:” 123123123" , “status_login”:真}, “诺姆”: “jijo”, “sexo”: “Masculino”, “sobrenome”: “jdiasjdia”}
答案 0 :(得分:0)
List<string> urls = xmldoc2.Descendants("PID").Select(x => x.Attribute("5678").Value).ToList();
<Tools>
<Tools>
<Tool>
<ID>1234</ID>
<PID>5678</PID>
<Name>Test</Name>
</Tool>
</Tools>
<Type>
<Parent>
<ID>5678</ID>
<PID>9999</PID>
<Name>Test2</Name>
</Parent>
</Type>
</Tools>
,您需要对其进行解码。$fk_login_cidadao = json_decode( $request->getParam('cidadao') );