Home  >  Article  >  Backend Development  >  php做项目进行中英文的切换,如何快速实现

php做项目进行中英文的切换,如何快速实现

WBOY
WBOYOriginal
2016-06-23 13:42:551818browse

这个是我在做项目的时候总结的方法,当然如果你们有更好的方法也可以和我分享一下

一般我会建议建2个文件,一个中文的一个英文的

在视图页面:

<div class="top">      <div class="contenters">        <a href="<?php echo APP::URL($page,array('language'=>'cn')); ?>">中文</a>        <a href="<?php echo APP::URL($page,array('language'=>'en')); ?>">English</a>      </div></div>

在控制器页面:

$page = 'newexhibitors';if(isset($_GET['language'])){   if($_GET['language']=='cn'){       $_SESSION['lan'] = 'cn';       $title = '测试';       require APP::TPL('newexhibitors');   }else if($_GET['language']=='en'){       $_SESSION['lan'] = 'en';       $title = 'Test';       require APP::TPL('en_newexhibitors');   }}else{    if($_SESSION['lan']){       if($_SESSION['lan']=='cn'){            $title = '测试';            require APP::TPL('newexhibitors');       }else{            $title = 'Test';            require APP::TPL('en_newexhibitors');       }    }else{       $_SESSION['lan']='cn';       $title = '测试';       require APP::TPL('newexhibitors');    }}

这个代码实现的效果,点击“中/英”文切换时,自动在当前页面进行切换

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn