【www.gdgbn.com--smarty模板】

smarty smarty syntax error: invalid attribute name

Smarty error: [in file:xx.tpl line 1]: syntax error: invalid attribute name: "index.tpl" (Smarty_Compiler.class.php, line 1521)

//当你遇到这个错误时,说明你的magic_quotes_runtime设置是打开的在你的php.ini配置文件.

//smarty需要在这个值是关闭的时候才能运行

//切勿将magic_quotes_runtime打开与magic_quotes_gpc的值相混淆(言外之意就是两个设置是不一样的)smarty只需要将magic_quotes_runtime关闭就可以了

If you encounter an error like this, then you have magic_quotes_runtime turned on in you php.ini. Smarty needs this value to be turned off to operate properly.

Don"t mix magic_quotes_runtime up with magic_quotes_gpc .

Smarty only needs the former to be off.

//假如你无法更改php.ini在你的web配置当中,你可以用ini_set("magic_quotes_runtime", false);在程序运行时将其关闭

If you don"t have access to your php.ini or to your webserver-configuration, then you can turn magic_quotes_runtime off at runtime with

[php:1:b7ea9ca818]ini_set("magic_quotes_runtime", false);[/php:1:b7ea9ca818]

//但最好是在配置文件中将其关闭。


But it"s best to simply bother your system-administrator to turn it off globally.

我是通过这样来将其关闭的。

if(get_magic_quotes_runtime())
{
 set_magic_quotes_runtime(0);
}

因为这个设置在有些版本的配置里面他是关闭的,就比如我在家里的那台电脑的php运行环境默认就是关闭的,所以我在smarty里使用include函数就不会报错。get_magic_quotes_runtime设置打开时为1否则为0

这条语句就是先判断下,是否打开,如果有的话就将其关闭,另外只要把ini_set("magic_quotes_runtime", false);这条语句或是用我上面的方法, 放在smarty的配置文件中就没问题了。

每次引入时自动判断了。


因为打开的作用还是有的。


几天碰到了怪事,css文件定义的居中使用smaty解析后,不起作用,为左对齐。
如下,其中的css代码:
#center{width:930px;margin:0 auto;padding:0;font-size:14px;clear:both;}/* 主体 */
按常理,



内容

内容应该居中对齐,可是死活不行。
查看php文件,是utf-8编码,模板文件也是utf-8编码,php文件包含的其他文件也都是utf-8编码,但我注意到包含的Smarty.class.php是英文字符的,不存在编码问题,应该不是smarty的问题,所以也没在意。

下午,我用排除法,把包含的文件全部去除,只留下require SMARTY_DIR.’Smarty.class.php’;  和相关php语句,但还是老样子。
后来,我想起了缓存文件,因为smarty解析后生成缓存文件,出现对不齐的怪事应该可以从缓存文件里再判断,看缓存文件是否正常,打开templates_c目录,用EmEditor点开生成的文件,看了看没有发现什么可疑之处,但瞟了一下编码,发现也是utf-8编码(跟随php文件编码方式,php文件什么编码,它就是什么编码),但发现它是“不带签名”的方式,Smarty.class.php也是不带签名的方式,所以我把php文件和该php文件包含的其他文件都改成了不带签名的文件后,刷新,呵呵,成功了!

结论:

不但编码方式要一致,带不带签名也要一致!smarty是不带签名的方式所以,模板、css文件、php文件等都得是不带签名方式的。

 
 
我是因为用的dreamweaver的关系 当中自带了两行这个,

本文来源:http://www.gdgbn.com/jiaocheng/22786/