I have a function that creates an xml from a collection of laravel, however, I would like, in the end, save the file to later send by email, but I can not save.
Here is the function that creates xml:
private function exportXMLMIndependente($title, $collection){
$xml = new \XMLWriter();
$xml->openMemory();
$xml->startDocument('1.0', 'ISO-8859-15', 'yes');
$xml->startElement('candidatos');
foreach($collection as $candidato) {
if($candidato->tipo_id){
$tipo_id = "carteiraIdentidade";
}else{
$tipo_id = "passaporte";
}
$xml->startElement('candidato');
$xml->writeAttribute('idCandidato', $candidato->id);
$xml->writeAttribute('nome', $candidato->name);
$xml->writeAttribute('genero', $candidato->genre);
$xml->writeAttribute('nacionalidade', $candidato->nationality->name);
$xml->writeAttribute('dataNascimento', $candidato->birthdate);
$xml->writeAttribute('tipoIdentificacao', $tipo_id);
$xml->writeAttribute('numeroIdentificacao', $candidato->id_number);
$xml->writeAttribute('cpf', $candidato->cpf);
$xml->writeAttribute('validadeID', $candidato->id_validate_date);
$xml->writeAttribute('morada', $candidato->address);
$xml->writeAttribute('localidade', $candidato->city);
$xml->writeAttribute('codPostal', $candidato->postal_code);
$xml->writeAttribute('pais_residencia', $candidato->country->name);
$xml->writeAttribute('indicativoTlf', $candidato->indicative);
$xml->writeAttribute('numTelefone', $candidato->phone);
$xml->writeAttribute('email', $candidato->email);
$xml->writeAttribute('codCurso', $candidato->curso->cod_curso);
$xml->writeAttribute('docID', $candidato->doc_id);
$xml->writeAttribute('fileConclusaoCursoSuperior', $candidato->doc_certidao_curso_superior);
$xml->writeAttribute('fileCertidaoUnidadesCurriculares', $candidato->doc_certidao_un_curriculares);
$xml->writeAttribute('fileCV', $candidato->doc_cv);
$xml->writeAttribute('fileCVPersonalizado', $candidato->doc_cv_personalizado);
$xml->writeAttribute('filePortfolio', $candidato->doc_portfolio);
$xml->writeAttribute('fileCartaRecomendacao', $candidato->doc_carta_recomendacao);
$xml->writeAttribute('fileCartaMotivacao', $candidato->doc_carta_motivacao);
$xml->writeAttribute('filePropostaProjeto', $candidato->doc_proposta_projeto);
$xml->writeAttribute('fileCertificadoEN', $candidato->doc_certificado_en);
$xml->writeAttribute('fileFotografia', $candidato->doc_fotografia);
$xml->writeAttribute('pagSucesso', $candidato->pagamento_sucesso);
$xml->startElement('linguas');
foreach ($candidato->languages as $lingua){
$xml->startElement('lingua');
$xml->writeAttribute('nome', $lingua->name);
$xml->writeAttribute('nivel', $lingua->nivel);
$xml->endElement();
}
$xml->endElement();
$xml->startElement('ramos');
foreach ($candidato->ramos as $ramo){
$xml->startElement('ramo');
$xml->writeAttribute('cod_ramo', $ramo->cod_ramo);
$xml->writeAttribute('nome', $ramo->name);
$xml->writeAttribute('opcao', $ramo->option);
$xml->endElement();
}
$xml->endElement();
$xml->endElement();
}
$xml->endElement();
$xml->endDocument();
//$xml->flush();
$content = $xml->outputMemory(true);
$xml = null;
return $content;
//$content = $xml->outputMemory();
//$xml = null;
//return response($content)->header('Content-Type', 'text/xml');
}
At this point it exports me a string with xml
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2tE5o1Y
via IFTTT
Aucun commentaire:
Enregistrer un commentaire