THINKPHP 解决模块不存在时出现空页面的问题

遇到的问题:
最近使用THINKCMF开发了一个企业网站,因为之前客户的域名变更过,然后就发现当某个模块不存在的时候就出现了空页面
THINKPHP论坛 上有人说在项目里添加一个EmptyAction.class.php,然后再写业务逻辑,结果搞了好长时间我一直都没有找到Action目录
最后才发现ThinkCmf使用的是Thinkphp3.2而作者写的是3.1
在网上逛了半天也没有解决问题,不得已还是要自己出马
 
解决方案:
  1. \application\Common\Controller\目前添加“EmptyBaseController.class.php”文件              
  1. <?php/**
    *@Author:HTL
    *@Email:[email protected]
    *@DateTime:2015-07-1411:22:18
    *@Description:空模板控制器
    *@use:其他项目添加EmptyController文件并继承该类即可
    */namespace Common\Controller;useThink\Controller;class EmptyBaseController extendsController{function_initialize(){//项目配置文件中的配置项
    $emptyPath=C("EMPTY_PATH");//如果未配置默认的地址
    if(!$emptyPath || empty($emptyPath))$emptyPath="/";header("Location:".$emptyPath);exit();
    }
    }
     

     

     2.在所有项目的Controller目前里添加EmptyController.class.php并继承”\Common\Controller\EmptyBaseController“               
  1. <?php/**
    *@Author:HTL
    *@Email:[email protected]
    *@DateTime:2015-07-1411:22:18
    *@Description:空模板控制器,直接继承\Common\Controller\EmptyBaseController即可
    */namespace Portal\Controller;class EmptyControllerextends \Common\Controller\EmptyBaseController{
    function _initialize(){
    parent::_initialize();
    }
    }

     

      3.在\data\conf\config.php里添加" EMPTY_PATH "项自定义当访问不存在的模块时需要跳转的页面          
  1. <?php return array('EMPTY_PATH'=>'/index.php',/*访问不存在的模块时跳转的地址*/
    //其他配置项
    );?
    >
 
参考:

 

你可能感兴趣的:(thinkphp)