?
本文檔使用 PHP中文網(wǎng)手冊(cè) 發(fā)布
Smarty - the compiling PHP template engine | ||
---|---|---|
Prev 來(lái)源: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允許通過(guò)模板訪問(wèn)PHP對(duì)象。有兩種方式來(lái)訪問(wèn)它們。一種是注冊(cè)對(duì)象到模板,然后通過(guò)類似于用戶自定義函數(shù)的形式來(lái)訪問(wèn)它。另一種方法給模板分配對(duì)象,然后通過(guò)訪問(wèn)其它賦值變量類似的方法進(jìn)行訪問(wèn)。第一種方法有一個(gè)很好的模板語(yǔ)法,同時(shí)它作為一個(gè)注冊(cè)對(duì)象被限制為幾個(gè)固定的方法和目標(biāo),這樣是比較安全的。然而一個(gè)注冊(cè)對(duì)象不能夠在相對(duì)自身數(shù)組里面循環(huán)使用和賦值??傊?,你根據(jù)你自己的需求來(lái)覺(jué)得選用那種方法,但是使用第一種方法的話,可以讓你的模伴語(yǔ)法達(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)激活后,就沒(méi)有私有成員或者函數(shù)能夠被訪問(wèn)(以"_"開(kāi)頭)。如果有一個(gè)同名成員或者對(duì)象存在,那么方法將被使用。
You can restrict the methods and properties that can be accessed by listing them in an array as the third registration parameter.
你可以限制成員和函數(shù),但是外解可以通過(guò)列舉它們?yōu)橐粋€(gè)第三注冊(cè)變量的數(shù)組的方式來(lái)訪問(wèn)它。
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ù)通過(guò)模板傳遞給對(duì)象的方法和自定義函數(shù)獲得參數(shù)的方法是一樣的。一個(gè)混合數(shù)組作為第一個(gè)參數(shù)傳遞,而SMARTY對(duì)象作為第二個(gè)。如果你想像傳統(tǒng)的對(duì)象參數(shù)一樣一次傳遞一個(gè)參數(shù),設(shè)置第四個(gè)參數(shù)為 FALSE即可。
Example 15-1. using a registered or assigned object
|
Prev 來(lái)源:PHP中文社區(qū) | Home | Next |
Cache Groups | Up | Prefilters |