I have a list of songs being fetched from the database. Some of this songs have the first letter with an accent. I have normalized the alpha pagination and I get the following pagination;
Pagination all - A - E.
and I have the following list of songs;
A Hora é Essa
É de Manhã
Eu Testo
When I click on the "E" link, I only get the "Eu testo", the other one "É de Manhã" does not show. I need that the links with accent and without to be together. My code is as follow
SongsController
public function actionIndex()
{
if( !Yii::app()->user->checkAccess("admin") )
{
$this->layout = 'user_view';
}
Yii::import('application.extensions.alphapager.ApPagination');
Yii::import('application.extensions.alphapager.ApArrayDataProvider');
$criteria=new CDbCriteria;
$criteria->order = 'title asc';
$criteria->addCondition('live = "1"');
// The constructor takes the name of the models attribute to which the condition should be applied when using applyCondition().
// Here we'll select the output by 'title'-attribute of our model
$alphaPages = new ApPagination('title');
$pages = $alphaPages->pagination;
//$alphaPages->applyCondition($criteria);
$pages->setItemCount(Songs::model()->count($criteria));
//$pages->applyLimit($criteria);
//$pages->setPageSize(10);
$criteria_letter=new CDbCriteria;
$criteria_letter->select='DISTINCT(SUBSTR(`title`,1,1)) AS `title` '; // replace 'name' to ur search field
$criteria_letter->addCondition('live = "1"');
$criteria_letter->order = 'title asc';
$chars =Songs::model()->findAll($criteria_letter);
foreach($chars as $char){
$string= ($char->title);
$activeChars[]=mb_strtoupper($this->remove_accents($string));
}
$rawData=Songs::model()->findAll($criteria);
$dataProvider=new ApArrayDataProvider($rawData, array(
'alphapagination'=>array(
'attribute'=>'title',
'charSet' => $activeChars,
'activeCharSet'=>$activeChars,
'pagination'=>array(
'pageSize'=>7,
),
),
'pagination' => false,
));
$this->render('index',array(
'dataProvider'=>$dataProvider,
'alphaPages'=>$alphaPages,
//'pages'=>$pages,
));
}
The Function to normalize the character
public function remove_accents($string) {
$string = $string;
$normalizeChars = array( 'Š'=>'S', 'š'=>'s', 'Ð'=>'Dj','Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss','à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y', 'ƒ'=>'f', 'ă'=>'a', 'î'=>'i', 'â'=>'a', 'ș'=>'s', 'ț'=>'t', 'Ă'=>'A', 'Î'=>'I', 'Â'=>'A', 'Ș'=>'S', 'Ț'=>'T', );
return strtr($string, $normalizeChars); }
My _view
<div id="box_hover" >
<?php echo CHtml::link(CHtml::encode($data->title), array('view', 'id'=>$data->id)); ?> by <?php echo CHtml::link(CHtml::encode($artists_name->name), array('/artists/view', 'id'=>$artists_name->id)); ?> <?php if(!empty($data->url)):?><?php echo CHtml::link($image,array('view', 'id'=>$data->id)); ?> <?php endif;?>
The DB is set to UTF8_unicode_ci. Any help will be much appreciated!