Home  >  Article  >  Backend Development  >  php—Smarty-2 (19),phpsmarty-219_PHP教程

php—Smarty-2 (19),phpsmarty-219_PHP教程

WBOY
WBOYOriginal
2016-07-13 09:54:571028browse

php—Smarty-2 (19),phpsmarty-219

1、  分界符

l  left_delimiter

l  right_delimiter

Smarty默认分界符是:”{“,”}”

如果需要改变,可以设置上面两个属性

模板代码:

程序代码:

1、  模板变量赋值

Assign方法两个参数

1)  模板变量名

2)  值

一、 路径设置

1、  Smarty中的几个常用路径

1)  模板路径           template_dir

2)  编译路径           compile_dir

3)  配置文件路径       config_dir

4)  缓存文件路径       cache_dir

以上四个路径是smarty类下的四个属性

2、  在Smarty2.6中,这几个属性可以在类外设置的

Class Smarty{

     Var $template_dir;

     Var $compile_dir;

     Var $config_dir;

     Var $cache_dir;

}

3、  在Smarty3.0中,这个属性是这样定义的:

protected $template_dir

protected $compile_dir

这里定义成了受保护成员,也就是说,我们可以继承smarty类,然后可以拥有这几个受保护成员。

 

在这里,我们发现,可以直接设置这几个受保护成员。

当为一个不存在或不可访问的成员赋值时,自动执行set

当对一个不存在或不可访问的成员取值时,自动执行get

当取值或赋值时,首先检查,方法中$allowed数组是否定义该元素,如果定义过,则直接调用该数组元素对应的smarty方法

通过以上代码,可以得知,在smarty3.0中,有八个方法专门针对于这四个属性取值和赋值

l  setTemplateDir()

l  setCompileDir()

l  setConfigDir()

l  setCacheDir()

l  getTemplateDir()

l  getCompileDir()

l  getConfigDir()

l  getCacheDir()

建议大家使用以上方法进行路径设置

在Smarty的构造方法中,为以上四个属性设置了默认值。

通过以上程序输出smarty默认路径

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/993274.htmlTechArticlephp—Smarty-2 (19),phpsmarty-219 1、 分界符 l left_delimiter l right_delimiter Smarty默认分界符是:{,} 如果需要改变,可以设置上面两个属性 模板代...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn