【问题标题】:Windows 8.1 XAMPP and smartyWindows 8.1 XAMPP 和 smarty
【发布时间】:2014-06-16 07:53:07
【问题描述】:

我已经安装并配置了 XAMPP。我正在尝试安装Smarty 3.1.18,但遇到了一些问题。

我已更改我的php.ini 文件以将 smarty/libs 目录添加到包含中。 我已将 smarty 解压缩到我的 c:\smarty 文件夹中 我在 htdocs 文件夹中创建了 smarty\templatesconfig 文件夹 我还在c:\smarty 文件夹中创建了我的缓存和templates_c 文件夹。 我制作了我的index.php 文件以包含所有目录,并制作了我的index.tpl 文件并将其放在我的模板文件夹中。 当我运行 index.php 文件时,我返回:

致命错误:未捕获 --> Smarty:无法加载模板文件 'index.tpl'

有什么想法吗??

我已经运行了testinstall() 脚本,这就是它返回的内容:

Smarty Installation test...
Testing template directory...
FAILED: .\templates\ does not exist.
Testing compile directory...
FAILED: .\templates_c\ does not exist.
Testing plugins directory...
C:\smarty\libs\plugins is OK.
Testing cache directory...
FAILED: .\cache\ does not exist.
Testing configs directory...
FAILED: .\configs\ does not exist.
Testing sysplugin files...
... OK
Testing plugin files...
... OK
Tests complete.

我已经检查并重新检查了我的文件位置和目录位置,这就是它们所在的位置:

$smarty->template_dir = 'c:/xampp/htdocs/smarty/templates';
$smarty->config_dir = ' c:/xampp/htdocs/smarty/config';
$smarty->cache_dir = 'c:/smarty/cache';
$smarty->compile_dir = 'c:/smarty/templates_c';

【问题讨论】:

  • 请提供代码如何为 Smarty 类设置模板目录
  • 好吧,无论是谁编辑了我的问题,它现在都没有意义......

标签: php smarty windows-8.1 smarty3


【解决方案1】:

您应该做的是使用以下方法为模板、templates_c、缓存和配置设置正确的路径:

$smarty->setTemplateDir('full_xampp_project_path/templates');
$smarty->setCompileDir('c:\smarty\templates_c');
$smarty->setConfigDir('full_xampp_project_path/config');
$smarty->setCacheDir('c:\smarty\cache');

作为full_xampp_project_path,您应该提供项目所在的完整路径,例如c:/xampp/htdocs/yourproject

当您在 c:\smarty 中解压缩 smarty 并将您的项目放在例如 c:/xampp/htdocs/yourproject` 中时,您需要手动设置这些目录。

您应该确保所有路径都确实存在。

编辑

我刚刚测试了类似的配置,但没有更改 php.ini 中的任何内容,因为它实际上是不必要的。我将 Smarty 放入 c:\smarty 并在那里创建了 templates_ccache 目录,我的 Web 服务器目录内还有 templatesconfigs 目录。

我使用以下代码:

<?php

require 'c:\smarty\Smarty.class.php';

$smarty = new Smarty;
$smarty->setTemplateDir('D:\DaneAplikacji\WampServer\www\smarty\demo\templates');
$smarty->setCompileDir('C:\smarty\templates_c');
$smarty->setConfigDir('D:\DaneAplikacji\WampServer\www\smarty\demo\configs');
$smarty->setCacheDir('C:\smarty\cache');

$smarty->testInstall();
$smarty->display('demo.tpl');

一切正常。输出是:

Smarty Installation test...
Testing template directory...
D:\DaneAplikacji\WampServer\www\smarty\demo\templates is OK.
Testing compile directory...
C:\smarty\templates_c is OK.
Testing plugins directory...
C:\smarty\plugins is OK.
Testing cache directory...
C:\smarty\cache is OK.
Testing configs directory...
D:\DaneAplikacji\WampServer\www\smarty\demo\configs is OK.
Testing sysplugin files...
... OK
Testing plugin files...
... OK
Tests complete.

demo

所以一切正常。您应该简单地使用我上面描述的方法来设置目录并确保这些目录存在。

【讨论】:

  • 您好,注意:未定义的索引:C:\xampp\smarty\templates_c\5afa44c5bb5ef66ed311d96647082148d7699422.file.demo.tpl.php 中的名称第 28 行注意:试图在 C 中获取非对象的属性:\xampp\smarty\templates_c\5afa44c5bb5ef66ed311d96647082148d7699422.file.demo.tpl.php 在第 28 行
  • 这就是我得到的回报。
  • 我弄清楚了问题所在。使用您的一些代码行,只需制作一个简单的 demo.tpl 文件,我就让它工作了。感谢您的知识和时间。
猜你喜欢
  • 2016-05-30
  • 2015-08-01
  • 2014-09-28
  • 1970-01-01
  • 2015-09-16
  • 1970-01-01
  • 1970-01-01
  • 2015-11-08
  • 2014-11-21
相关资源
最近更新 更多