mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-02 13:12:49 +08:00
TP4初始版本提交
This commit is contained in:
48
Library/Think/Behavior/LocationTemplate.php
Normal file
48
Library/Think/Behavior/LocationTemplate.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?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';
|
||||
return $templateFile;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user