onethink 多语言 多模板 切换
浏览:8395
最后更新:2014-09-25 15:32
分类:示例
作者寄语:
大家来研究
<a class="ajax-get" href="{:U('User/setlng?lng=cn')}">中文 </a>
<a class="ajax-get" href="{:U('User/setlng?lng=en')}">English </a>
切换语言操作,我是放在 user 里 public function setlng(){
$lng = I('get.lng');
$lng=empty($lng) ? 'cn' : $lng;
cookie('admin_lng',$lng);
$this->success('成功切换内容语言为'.$lng);
//echo $lng;
}
修改 AdminController.class.php 设置当前语言在
protected function _initialize(){
里添加// 获取当前语言
$lng=cookie('admin_lng');
$lng= empty($lng) ? "cn" : $lng;
define('LNG',$lng);
数据显示 修改文件 CategoryModel.class.php
自动处理
protected $_auto = array(
添加 array('lng', LNG, self::MODEL_INSERT),
public function getTree($id = 0, $field = true){修改
$map = array('status' => 1);
为$map = array('status' => 1,'lng' => LNG);
-----------------------------------------------------------------------------------------接下来如果希望在内容页只显示当前语言的分类 也很简单
ArticleController.class.php
protected function getMenu(){
里找到 102 行
$cate = M('Category')->where(array('status'=>1))->field('id,title,pid,allow_publish')->order('pid,sort')->select();
改成 $cate = M('Category')->where(array('status'=>1,'lng' => LNG))->field('id,title,pid,allow_publish')->order('pid,sort')->select();
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------切换模板操作,
<a class="ajax-get" href="{:U('index/settpl?tpl=default')}">默认</a>
<a class="ajax-get" href="{:U('index/settpl?tpl=MM')}">mm</a>
home\IndexController.class.php
public function settpl(){
$tpl= I('get.tpl');
$tpl=empty($tpl) ? 'default' : $tpl;
cookie('home_tpl',$tpl);
$this->success('成功切换模板为'.$tpl);
}
修改 home\HomeController.class.php 设置当前模板在
protected function _initialize(){
里添加 $tpl=cookie('home_tpl'');
$tpl= empty($tpl) ? "default" : $tpl;
C('DEFAULT_THEME','MM');