Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复试图调用方法没达到文档预期效果的问题; #2692

Open
wants to merge 1 commit into
base: 6.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/think/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// +----------------------------------------------------------------------
// | Author: liu21st <[email protected]>
// +----------------------------------------------------------------------
declare (strict_types = 1);
declare(strict_types=1);

namespace think;

Expand Down Expand Up @@ -39,11 +39,18 @@ class View extends Manager
* 获取模板引擎
* @access public
* @param string $type 模板引擎类型
* @param bool $return_driver 是否返回引擎驱动
* @return $this
*/
public function engine(string $type = null)
public function engine(string $type = null, bool $return_driver = false)
{
return $this->driver($type);
$driver = $this->driver($type);

if ($return_driver) {
return $driver;
}

return $this;
}

/**
Expand Down Expand Up @@ -87,7 +94,7 @@ public function filter(callable $filter = null)
public function fetch(string $template = '', array $vars = []): string
{
return $this->getContent(function () use ($vars, $template) {
$this->engine()->fetch($template, array_merge($this->data, $vars));
$this->engine(null, true)->fetch($template, array_merge($this->data, $vars));
});
}

Expand All @@ -101,7 +108,7 @@ public function fetch(string $template = '', array $vars = []): string
public function display(string $content, array $vars = []): string
{
return $this->getContent(function () use ($vars, $content) {
$this->engine()->display($content, array_merge($this->data, $vars));
$this->engine(null, true)->display($content, array_merge($this->data, $vars));
});
}

Expand Down Expand Up @@ -187,5 +194,4 @@ public function getDefaultDriver()
{
return $this->app->config->get('view.type', 'php');
}

}