Senin, 31 Desember 2018

Joomla 3.x feature, display list of items from csv file

This feature can be used alone, to display file, or to integrate it with upload feature for review or  confirmation, before data is imported to database.

For the file to be displayed, I hardcode "tmp/datax.csv". You can change it to the file you wanna open, or selectable by user once you integrate it with other function.


these are the codes put in the controller:
function export_displaynow()
{


$validate = 1;//default success -- meanwhile dont do anything
$message = JText::_('COM_TESTDATA_SUCCESSFUL_POST');//default message
//validation process below is working 28/12
$db = JFactory::getDbo();
$query = $db->getQuery(true);

$row = 1;
if (($handle = fopen("tmp/datax.csv", "r")) !== FALSE) { // datax.csv to be customized.
echo '<table>';
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
echo '<tr> <td>';
echo "<p> $num fields ind line $row: </p>";
$row++;
$disp = $data;
for ($c=0; $c < $num; $c++) {
echo '<td>';
echo $data[$c] . "<br />\n";
echo '</td>';
}
echo '</tr>';
}
echo '</table>';
fclose($handle);
}


return $disp;
$this->input->set('view', 'exportlist');

parent::display($cachable = false, $urlparams = false);
}

Tidak ada komentar: