阅读:714
回复:0
根据不同模板参数显示调用不同模板目录修改1: thinkphp/library/think/Controller.php public function __construct(Request $request = null) { $this->request = is_null($request) ? Request::instance() : $request; $this->request->isAjax() ? define('IS_AJAX',true) : define('IS_AJAX',false); // ($this->request->method() == 'GET') ? define('IS_GET',true) : define('IS_GET',false); // ($this->request->method() == 'POST') ? define('IS_POST',true) : define('IS_POST',false); // if (I('gettemplate')!='' && strtolower($this->request->module()) == 'mobile'){ $key=I('gettemplate'); $arr = scandir("./template/mobile/"); foreach ($arr as $k => $val) { if ($val == '.' || $val == '..' || strstr($val,'svn')|| strstr($val,'DS_Store')) continue; $template[] = $val; } if(in_array($key, $template)) { $gettemplate_a=Array( 'type'=> 'Think', 'view_path' => './template/mobile/'.$key.'/', 'view_suffix' => 'html', 'tpl_begin' => '{', 'tpl_end' => '}', 'taglib_begin' => '<', 'taglib_end' => '>', 'default_theme' =>$key, 'view_depr'=>"/", ); $gettemplate_b= Array ( '__PUBLIC__' => '/public', '__STATIC__' => '/template/mobile/'.$key.'/static', '__ROOT__' => '' ); session('gettemplate_a', $gettemplate_a); session('gettemplate_b', $gettemplate_b); }; } if (session('gettemplate_a')!='' && session('gettemplate_b')!='' && strtolower($this->request->module()) == 'mobile'){ session('gettemplate_a',session('gettemplate_a')); session('gettemplate_b', session('gettemplate_b')); $this->view = View::instance(session('gettemplate_a'), session('gettemplate_b')); } else{ $this->view = View::instance(Config::get('template'), Config::get('view_replace_str')); } define('MODULE_NAME',$this->request->module()); // 当前模块名称是 define('CONTROLLER_NAME',$this->request->controller()); // 当前控制器名称 define('ACTION_NAME',$this->request->action()); // 当前操作名称是 define('PREFIX',C('database.prefix')); // 数据库表前缀 $this->assign('action',ACTION_NAME); $this->assign('template_now_time', time());//模板现在时间 if(isMobile() && strtolower(MODULE_NAME) == 'home' && strtolower(CONTROLLER_NAME) == 'index' && strtolower(ACTION_NAME) == 'index') { header("Location: ".U('Mobile/Index/index')); exit(); } read_html_cache(); // 尝试从缓存中读取 // 自动清除缓存 // if(rand(1,100) == 100) // { // delFile(RUNTIME_PATH); // Cache::clear(); // } // 控制器初始化 $this->_initialize(); // 前置操作方法 if ($this->beforeActionList) { foreach ($this->beforeActionList as $method => $options) { is_numeric($method) ? $this->beforeAction($options) : $this->beforeAction($method, $options); } } } 修改2 thinkhphp/library/think/Template.php 1090行。 //throw new TemplateNotFoundException('template not exists:' . $template, $template); 把这行注了,不知为什么,有时会服找不到模板,今天测试不知是不是有缓存原因,先注了, 没时间测试, 或是不注看看。 3,用法。 /mobile/Index/index/gettemplate/default URL后面,加gettemplate=模板目录名,只要一次,后面保存在 session |
|
|
您需要登录后才可以回帖,登录
|