?
Dieses Dokument verwendet PHP-Handbuch für chinesische Websites Freigeben
Smarty - the compiling PHP template engine | ||
---|---|---|
Prev 來源:PHP中文社區(qū) | Next |
Smarty allows access to PHP objects through the templates. There are two ways to access them. One way is to register objects to the template, then use access them via syntax similar to custom functions. The other way is to assign objects to the templates and access them much like any other assigned variable. The first method has a much nicer template syntax. It is also more secure, as a registered object can be restricted to certain methods or properties. However, a registered object cannot be looped over or assigned in arrays of objects, etc. The method you choose will be determined by your needs, but use the first method whenever possible to keep template syntax to a minimum.
SMARTY允許通過模板訪問PHP對象。有兩種方式來訪問它們。一種是注冊對象到模板,然后通過類似于用戶自定義函數(shù)的形式來訪問它。另一種方法給模板分配對象,然后通過訪問其它賦值變量類似的方法進(jìn)行訪問。第一種方法有一個很好的模板語法,同時它作為一個注冊對象被限制為幾個固定的方法和目標(biāo),這樣是比較安全的。然而一個注冊對象不能夠在相對自身數(shù)組里面循環(huán)使用和賦值。總之,你根據(jù)你自己的需求來覺得選用那種方法,但是使用第一種方法的話,可以讓你的模伴語法達(dá)到最小。
If security is enabled, no private methods or functions can be accessed (begininning with "_"). If a method and property of the same name exist, the method will be used.
如果安全選項(xiàng)激活后,就沒有私有成員或者函數(shù)能夠被訪問(以"_"開頭)。如果有一個同名成員或者對象存在,那么方法將被使用。
You can restrict the methods and properties that can be accessed by listing them in an array as the third registration parameter.
你可以限制成員和函數(shù),但是外解可以通過列舉它們?yōu)橐粋€第三注冊變量的數(shù)組的方式來訪問它。
By default, parameters passed to objects through the templates are passed the same way custom functions get them. An associative array is passed as the first parameter, and the smarty object as the second. If you want the parameters passed one at a time for each argument like traditional object parameter passing, set the fourth registration parameter to false.
一般情況下,參數(shù)通過模板傳遞給對象的方法和自定義函數(shù)獲得參數(shù)的方法是一樣的。一個混合數(shù)組作為第一個參數(shù)傳遞,而SMARTY對象作為第二個。如果你想像傳統(tǒng)的對象參數(shù)一樣一次傳遞一個參數(shù),設(shè)置第四個參數(shù)為 FALSE即可。
Example 15-1. using a registered or assigned object
|
Prev 來源:PHP中文社區(qū) | Home | Next |
Cache Groups | Up | Prefilters |