Hi.
I need some help.
I have Contratos and it belongs to Empleados.
Empleados belongs to Cities.
In Contratos I do export CSV and with extract how can I get in
empleado.ciudad_nacimiento_id
empleado.ciudad_domicilio_id
The names of the city stored en Cities
Thanks.
public function export($id = null)
{
$estado = $this->Contratos->get($id);
$results = $this->Contratos->Find('all')
->contain(['Empresas','Empleados', 'Cargos','Epss', 'Afps', 'Ccfs','Fces', 'Arls', 'CentroCostos',
'EstadoContratos', 'TipoContratos', 'Ciudades'])
->where(['estado_contrato_id =' => $id]);
$header = [
'ID',
'EMPRESA',
'TIPO IDENTIFICACION',
'IDENTIFICACION',
'NOMBRES',
'APELLIDOS',
'SEXO',
'FECHA NACIMIENTO',
'CIUDAD NACIMIENTO',
'DIRECCION DOMICILIO',
'CIUDAD DOMICILIO',
'FECHA EXPEDICION ID',
'CIUDAD EXPEDICION ID',
];
$extract = [
'id',
'empresa.nombre_empresa',
'empleado.tipo_identificacion_id',
'empleado.identificacion',
'empleado.nombres',
'empleado.apellidos',
'empleado.sexo_id',
'empleado.fecha_nacimiento',
'empleado.ciudad_nacimiento_id',
'empleado.direccion_domicilio',
'empleado.ciudad_domicilio_id',
'empleado.fecha_expedicion',
'empleado.ciudad_expedicion_id',
];
$this->setResponse($this->getResponse()->withDownload('Contratos.csv'));
$this->set(compact('results'));
$this->viewBuilder()
->setClassName('CsvView.Csv')
->setOptions([
'serialize' => 'results',
'header' => $header,
'extract' => $extract,
'bom' => true,
]);
}