SwitchMobileTplBehavior.class.php 1.2 KB

12345678910111213141516171819202122232425
  1. <?php
  2. class SwitchMobileTplBehavior extends Behavior {
  3. //智能切换模板引擎
  4. public function run(&$params){
  5. if(isset($_SERVER['HTTP_CLIENT']) &&'PhoneClient'==$_SERVER['HTTP_CLIENT']){
  6. C('TMPL_ENGINE_TYPE','Mobile');
  7. define('IS_CLIENT',true);
  8. }else{
  9. define('IS_CLIENT',false);
  10. if('./client/'==TMPL_PATH){
  11. $find=APP_TMPL_PATH;
  12. $replace=__ROOT__.'/client/';
  13. $parse_string=C('TMPL_PARSE_STRING');
  14. if(is_null($parse_string)) $parse_string=array();
  15. //自动增加一个模板替换变量,用于修复SAE平台下模板中使用../Public 会解析错误的问题。
  16. C('TMPL_PARSE_STRING',array_merge($parse_string,array($find=>$replace)));
  17. //判断如果是云窗调试器访问跳转访问首页到client目录
  18. if(APP_DEBUG && ''==__INFO__ && preg_match('/android|iphone/i',$_SERVER['HTTP_USER_AGENT'])){
  19. redirect(__ROOT__.'/client');
  20. exit();
  21. }
  22. }
  23. }
  24. }
  25. }