<table cellspacing="0" cellpadding="0" border="0" width="100%" summary="Header navigation table"><tbody><tr><th align="center" colspan="3">Smarty - the compiling PHPtemplate engine</th> </tr><tr><td valign="bottom" align="left" width="25%"><a accesskey="P" href="api.config.load.html">Prev</a></td> <td valign="bottom" align="center" width="50%">Chapter 13. Smarty Class Methods()</td> <td valign="bottom" align="right" width="25%"><a accesskey="N" href="api.createtemplate.html">Next</a></td> </tr></tbody></table> # createData()[建立数据对象] Name createData() ― creates a data object 创建一个数据对象 Description string createData(object parent); string createData(); This creates a data object which will hold assigned variables. It uses the following parameters: parent is an optional parameter. It is an uplink to the main Smarty object, a another user-created data object or to user-created template object. These objects can be chained. Templates can access variables assigned to any of the objects in it's parent chain. Data objects are used to create scopes for assigned variables. They can be used to have controll which variables are seen by which templates. 本函数创建一个数据对象,并将该对象赋值给变量。参数介绍如下: “parent”是个可选参数。它负责上行链接主Smarty对象、另一个用户自建数据对象或用户自建模板对象。这些对象支持链式,模板可以访问赋值给其父链对象的变量。 数据对象为赋值变量创建作用域。它们可以用于控制哪些模板可以访问哪些变量。 <table class="EXAMPLE" cellspacing="0" cellpadding="0" border="0" width="100%"><tbody><tr><td> <div class="EXAMPLE"><strong><a name="AEN31314" id="AEN31314"/>Example 13.14. createData()</strong><b><br/></b><table width="100%" bgcolor="#e0e0e0" border="0"><tbody><tr><td> <pre class="PROGRAMLISTING">&lt;?phpinclude('Smarty.class.php');$smarty = new Smarty;// create data object with its private variable scope 创建一个私有变量作用域的数据对象$data = $smarty-&gt;createData();// assign variable to data scope 赋值变量拥有$data的作用域$data-&gt;assign('foo','bar');// create template object which will use variables from data object 使用来自数据对象的变量创建模版对象$tpl = $smarty-&gt;createTemplate('index.tpl',$data);// display the template 显示模板$tpl-&gt;display();?&gt;</pre></td> </tr></tbody></table><p> 参见<a href="api.display.html">display()</a>和<a href="api.createtemplate.html">createTemplate()</a>。</p> </div> </td> </tr></tbody></table> <table cellspacing="0" cellpadding="0" border="0" width="100%" summary="Footer navigation table"><tbody><tr><td valign="top" align="left" width="33%"><a accesskey="P" href="api.config.load.html">Prev</a></td> <td valign="top" align="center" width="34%"><a accesskey="H" href="index.html">Home</a></td> <td valign="top" align="right" width="33%"><a accesskey="N" href="api.createtemplate.html">Next</a></td> </tr><tr><td valign="top" align="left" width="33%">configLoad()<br/> 加载配置</td> <td valign="top" align="center" width="34%"><a accesskey="U" href="api.functions.html">Up</a></td> <td valign="top" align="right" width="33%">createTemplate()<br/> 建立模板</td> </tr></tbody></table>