Skip to content

Commit

Permalink
改进默认模板规则
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Jul 19, 2019
1 parent 4f34150 commit a0e783c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Think.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace think\view\driver;

use think\App;
use think\helper\Str;
use think\Template;
use think\template\exception\TemplateNotFoundException;

Expand Down Expand Up @@ -154,7 +155,15 @@ private function parseTemplate(string $template): string

if (0 !== strpos($template, '/')) {
$template = str_replace(['/', ':'], $depr, $template);
$controller = App::parseName($request->controller());
$controller = $request->controller();

if (strpos($controller, '.')) {
$pos = strrpos($controller, '.');
$controller = substr($controller, 0, $pos) . '.' . Str::snake(substr($controller, $pos + 1));
} else {
$controller = Str::snake($controller);
}

if ($controller) {
if ('' == $template) {
// 如果模板文件名为空 按照默认模板渲染规则定位
Expand All @@ -163,7 +172,7 @@ private function parseTemplate(string $template): string
} elseif (3 == $this->config['auto_rule']) {
$template = $request->action();
} else {
$template = App::parseName($request->action());
$template = Str::snake($request->action());
}

$template = str_replace('.', DIRECTORY_SEPARATOR, $controller) . $depr . $template;
Expand Down

0 comments on commit a0e783c

Please sign in to comment.