I have created my custom component for joomla 2.5 according to the MVC architecture
and called it "com_employees".
I have the model file called: "employeelistexcel.php" with a function "getdata()":
Code: Select all
public function getData(){
if (empty( $this->_data )){
$firstname = JRequest::getString('firstname', '');
$lastname = JRequest::getString('lastname', '');
if (!empty($firstname)){
$where_firstname = ' AND firstname like "%'. $firstname . '%"';
}
if (!empty($lastname)){
$where_lastname = ' AND lastname like "%'. $lastname . '%"';
}
$db = JFactory::getDBO();
$query = ' SELECT id,user_id,firstname,lastname
FROM bitnami_joomla.hr_employee
WHERE user_id>42 ' . $where_firstname . $where_lastname;
$this->_data = $this->_getList( $query );
}
return $this->_data;
}
Code: Select all
protected $params = null;
/**
* constructor (registers additional tasks to methods)
* @return void
*/
function __construct(){
parent::__construct();
// Set reference to parameters
$this->params = JComponentHelper::getParams( 'com_employees' );
//$dummy = $this->params->get('parm_text');
}
Code: Select all
class EmployeesViewEmployeelistExcel extends JViewLegacy{
function display($tpl = null){
$app = JFactory::getApplication();
$document = JFactory::getDocument();
$document->_styleSheets = array();
/*
// load component parameters
$params = JComponentHelper::getParams( 'com_employees' );
$params = $app->getParams( 'com_employees' );
$dummy = $params->get( 'dummy_param', 1 );
// load another model
JModelLegacy::addIncludePath(JPATH_SITE.'/components/com_employees/models');
$otherModel = JModelLegacy::getInstance( 'Record', 'RecordModel' );
*/
$data = $this->get('Data');
$this->assignRef('data', $data);
$pagination = $this->get('Pagination');
$this->assignRef('pagination', $pagination);
parent::display($tpl);
}
}
Code: Select all
header('Content-Encoding: UTF-8');
header('Content-Type: application/x-msexcel; charset=UTF-8; format=attachment;');
header("Content-disposition: attachment; filename=My_example.csv");
$utf8_text="id,user_id,firstname,lastname\n";
foreach ($this->data as $row) {
$utf8_text.=$row->id.",";
$utf8_text.=$row->user_id.",";
$utf8_text.=$row->lastname.",";
$utf8_text.=$row->middlename."\n";
}
$utf8_text = strip_tags($utf8_text);
echo "\xEF\xBB\xBF"; // UTF-8 BOM
echo $utf8_text;
you can see the file screenshot in attached image. Can anyone somehow help me to remove this html staff and display the data in unicode?