duanlang0025 2015-07-28 17:25
浏览 25

Yii字母数字分页与标准化重音字符问题

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!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题