我有一个从数据库中提取的歌曲列表。这些歌曲中的一些首字母带有重音。我已经对alpha分页进行了规范化,并得到以下分页;
分页 全部 - A - E.
我有以下歌曲列表;
HoraéEssa
ÉdeManhã
Eu Testo当我点击“E”链接时,我只得到“Eu testo”,另一个“ÉdeManhã”没有显示。我需要带有重音的链接而不是在一起。我的代码如下
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,
));
}
规范化角色的功能
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','Ì'=>'我','Í'=>'我','Î'=>'我', 'Ï'=>'我','Ñ'=>'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','ì'=>'我','í'=>'我','î'=>'我', 'ï'=>'我','ð'=>'o','ñ'=>'n','ò'=>'o','ó'=>'o', 'ô'=>'o','õ'=>'o','ö'=>'o','ø'=>'o','ù'=>'u', 'ú'=>'你','û'=>'你','ý'=>'y','ý'=>'y','þ'=>'b', 'ÿ'=>'y','ƒ'=>'f', 'ă'=>'a','î'=>'我',''=>'a','ş'=>'s','ţ'=>'t', 'Ă'=>'A','Î'=>'我','Â'=>'A','Ş'=>'S','Ţ'=>'T', );
return strtr($ string,$ normalizeChars); }
我的_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;?>
DB设置为UTF8_unicode_ci。任何帮助将不胜感激!