ubuntu下Smarty3 配置后 页面空白
今天学习了php 的smarty模板,在机器搭建的时候 ,按照教程下载了Smarty-3.1.21.tar.gz 解压后将lib文件放至/var/www/html/SM 并改变文件夹名为smarty 并在/var/www/html/SM 目录下创建templates templates_c两个文件夹 并修改权限至 drwxrwxrwx
在/var/www/html/SM 目录下新建php文件 index.php
<?php<br /><br /> <br /> require './smarty/Smarty.class.php' ;<br /> $smarty=new Smarty();<br /> $smarty->setTemplateDir('./templates');<br /> $smarty->setCompileDir('./templates_c');<br /> //print_r($smarty->setCompileDir());<br /> $smarty->assign('title',"dfdf");<br /> $smarty->assign('author',"dfdf");<br /> $smarty->assign('poem1',"dfdf");<br /> $smarty->assign('poem2',"dfdf");<br /> $smarty->assign('poem3',"dfdf");<br /> $smarty->assign('poem4',"dfdf");<br /> $smarty->display('Example1801.html');<br />?>
Copy after login
在/var/www/html/SM/templates 目录下新建html文件 Example1801.html
<html><br /><head><br /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><br /><title>第一个 Smarty程序</title><br /></head><br /><body><br /> <table border="1"><br /> <tr><br /> <td colspan="2" align="center">{$title}</td><br /> </tr><br /> <tr><br /> <td colspan="2">{$author}</td><br /> </tr><br /> <tr><br /> <td width="120">{$poem1}</td><br /> <td width="120">{$poem2}</td><br /> </tr><br /> <tr><br /> <td>{$poem3}</td><br /> <td>{$poem4}</td><br /> </tr><br /> </table><br /></body><br /></html>
Copy after login
浏览器上输入http://localhost/SM/index.php后显示空白页
运行print_r($smarty->setCompileDir());
显示
Smarty Object ( [auto_literal] => 1 [error_unassigned] => [use_include_path] => [template_dir:Smarty:private] => Array ( [0] => ./templates/ ) [joined_template_dir] => ./templates/ [joined_config_dir] => ./configs/ [default_template_handler_func] => [default_config_handler_func] => [default_plugin_handler_func] => [compile_dir:Smarty:private] => / [plugins_dir:Smarty:private] => Array ( [0] => /var/www/html/SM/smarty/plugins/ ) [cache_dir:Smarty:private] => ./cache/ [config_dir:Smarty:private] => Array ( [0] => ./configs/ ) [force_compile] => [compile_check] => 1 [use_sub_dirs] => [allow_ambiguous_resources] => [caching] => [merge_compiled_includes] => [inheritance_merge_compiled_includes] => 1 [cache_lifetime] => 3600 [force_cache] => [cache_id] => [compile_id] => [left_delimiter] => { [right_delimiter] => } [security_class] => Smarty_Security [security_policy] => [php_handling] => 0 [allow_php_templates] => [direct_access_security] => 1 [debugging] => [debugging_ctrl] => NONE [smarty_debug_id] => SMARTY_DEBUG [debug_tpl] => file:/var/www/html/SM/smarty/debug.tpl [error_reporting] => [get_used_tags] => [config_overwrite] => 1 [config_booleanize] => 1 [config_read_hidden] => [compile_locking] => 1 [cache_locking] => [locking_timeout] => 10 [template_functions] => Array ( ) [default_resource_type] => file [caching_type] => file [properties] => Array ( ) [default_config_type] => file [template_objects] => Array ( ) [cache_modified_check] => [registered_plugins] => Array ( ) [plugin_search_order] => Array ( [0] => function [1] => block [2] => compiler [3] => class ) [registered_objects] => Array ( ) [registered_classes] => Array ( ) [registered_filters] => Array ( ) [registered_resources] => Array ( ) [_resource_handlers] => Array ( ) [registered_cache_resources] => Array ( ) [_cacheresource_handlers] => Array ( ) [autoload_filters] => Array ( ) [default_modifiers] => Array ( ) [escape_html] => [start_time] => 1423049920.1225 [_file_perms] => 420 [_dir_perms] => 505 [_tag_stack] => Array ( ) [smarty] => Smarty Object *RECURSION* [_current_file] => [_parserdebug] => [merged_templates_func] => Array ( ) [template_class] => Smarty_Internal_Template [tpl_vars] => Array ( ) [parent] => [config_vars] => Array ( ) )
网上很多网友说是权限的问题,导致不能对templates_c进行写,我已经用chmod 777 更改权限,但是问题还是不能解决,希望有大神出来解答一下,刚刚使用ubuntu和接触php 还有很多不懂的东西,希望能得到解答。
------解决思路----------------------打开错误提示呢?有错误么?
------解决思路----------------------我指的是程序中ini_set("display_errors",1); error_reporting(E_ALL);的情况下,有没有报错。
这种smarty的空白页面,多半是目录的权限问题。不只是template_c,template, 父目录最起码也应该有x的权限,否则是无法写入的。