Skip to content

Commit

Permalink
改进模板渲染路径
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Sep 17, 2019
1 parent 6657c02 commit 41dd64d
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/Think.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ public function exists(string $template): bool
*/
public function fetch(string $template, array $data = []): void
{
if (empty($this->config['view_path'])) {
$view = $this->config['view_dir_name'];

if (is_dir($this->app->getAppPath() . $view)) {
$path = $this->app->getAppPath() . $view . DIRECTORY_SEPARATOR;
} else {
$appName = $this->app['request']->app();
$path = $this->app->getRootPath() . $view . DIRECTORY_SEPARATOR . ($appName ? $appName . DIRECTORY_SEPARATOR : '');
}

$this->config['view_path'] = $path;
$this->template->view_path = $path;
}

if ('' == pathinfo($template, PATHINFO_EXTENSION)) {
// 获取模板文件名
$template = $this->parseTemplate($template);
Expand Down Expand Up @@ -168,19 +182,19 @@ private function parseTemplate(string $template): string
list($app, $template) = explode('@', $template);
}

if ($this->config['view_path'] && !isset($app)) {
$path = $this->config['view_path'];
} else {
$appName = isset($app) ? $app : $request->app();
$view = $this->config['view_dir_name'];
if (isset($app)) {
$view = $this->config['view_dir_name'];
$viewPath = $this->app->getBasePath() . $app . DIRECTORY_SEPARATOR . $view . DIRECTORY_SEPARATOR;

if (is_dir($this->app->getAppPath() . $view)) {
$path = isset($app) ? $this->app->getBasePath() . ($appName ? $appName . DIRECTORY_SEPARATOR : '') . $view . DIRECTORY_SEPARATOR : $this->app->getAppPath() . $view . DIRECTORY_SEPARATOR;
if (is_dir($viewPath)) {
$path = $viewPath;
} else {
$path = $this->app->getRootPath() . $view . DIRECTORY_SEPARATOR . ($appName ? $appName . DIRECTORY_SEPARATOR : '');
$path = $this->app->getRootPath() . $view . DIRECTORY_SEPARATOR . $app . DIRECTORY_SEPARATOR;
}

$this->template->view_path = $path;
} else {
$path = $this->config['view_path'];
}

$depr = $this->config['view_depr'];
Expand Down

0 comments on commit 41dd64d

Please sign in to comment.