[英]I am unable to open file with \Template::instance()->render. I am getting the following error
It is giving me the following error, 这给了我以下错误,
[text] => Unable to open /home/mehul/www/portal.hsua.com.au/public_html/assets/templates.html [文本] =>无法打开/home/mehul/www/portal.hsua.com.au/public_html/assets/templates.html
This is the part of code which is causing the problem. 这是导致问题的代码部分。
$this->f3->set('const', $constants);
ob_start();
echo \Template::instance()->render('/home/mehul/www/portal.hsua.com.au/public_html/assets/templates.html');
$renderedView = ob_get_clean();
/*foreach ($variables as $varname => $variable) {
$this->f3->clear($varname);
}*/
return $renderedView;
The file might not exist 该文件可能不存在
you're opening the PHP file in your webbrowser PHP file is somewhere located in /var/www delivered by Nginx / Apache. 您正在网络浏览器中打开PHP文件PHP文件位于Nginx / Apache提供的/ var / www中。 If that's the case, your webserver probably has no access to open a file within your home directory.
在这种情况下,您的网络服务器可能无权打开主目录中的文件。
I recommend you put the template files next to your PHP file to make sure your webserver has access to it. 我建议您将模板文件放在PHP文件旁边,以确保您的网络服务器可以访问它。
The render()
methods concatenates the given template $file
with all template paths stored in the UI
system variable while searching for a valid file. 在搜索有效文件时,
render()
方法将给定的模板$file
与存储在UI
系统变量中的所有模板路径连接在一起。 Therefore you either have to specify a relative path or append /
as workaround. 因此,您必须指定相对路径或将
/
作为解决方法。
Workaround 解决方法
$f3 = Base::instance();
$f3->concat('UI', ';/');
Source/Reference 来源/参考
The concatination $dir.$file
in base.php#L2791 is the culprit. 罪魁祸首是base.php#L2791中的
$dir.$file
。 Your error is generated a few lines below. 您的错误在下面几行生成。
Update / Example 更新/示例
$f3 = Base::instance();
$f3->concat('UI', ';/'); // Add support for absolute paths.
echo \Template::instance()
->render(__DIR__ . '/template.html');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.