mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 20:52:48 +08:00
50 lines
1.8 KiB
PHP
50 lines
1.8 KiB
PHP
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2006-2012 http://thinkphp.cn All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
|
// +----------------------------------------------------------------------
|
|
// | Author: liu21st <liu21st@gmail.com>
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace Think\Behavior;
|
|
|
|
/**
|
|
* 系统行为扩展:定位模板文件
|
|
* @category Think
|
|
* @package Think
|
|
* @subpackage Behavior
|
|
* @author liu21st <liu21st@gmail.com>
|
|
*/
|
|
class LocationTemplate {
|
|
// 行为扩展的执行入口必须是run
|
|
public function run(&$templateFile){
|
|
// 自动定位模板文件
|
|
if(!is_file($templateFile))
|
|
$templateFile = $this->parseTemplateFile($templateFile);
|
|
}
|
|
|
|
/**
|
|
* 自动定位模板文件
|
|
* @access private
|
|
* @param string $templateFile 文件名
|
|
* @return string
|
|
*/
|
|
private function parseTemplateFile($template) {
|
|
$template = str_replace(':','/',$template);
|
|
if(''==$template) {
|
|
// 如果模板文件名为空 按照默认规则定位
|
|
$template = CONTROLLER_NAME.'/'.ACTION_NAME;
|
|
}elseif(false === strpos($template,'/')){
|
|
$template = CONTROLLER_NAME.'/'.$template;
|
|
}elseif(false === strpos($template,'.')) {
|
|
$template = $template;
|
|
}
|
|
$templateFile = MODULE_PATH.'view/'.$template.'.html';
|
|
if(!is_file($templateFile))
|
|
throw_exception(L('_TEMPLATE_NOT_EXIST_').'['.$templateFile.']');
|
|
return $templateFile;
|
|
}
|
|
} |