我是phptal的第一次用户,我无法使用phptal为输入框提供价值我有三个文件1.index.php
require_once 'includes/lib/PHPTAL-1.2.2/PHPTAL.php';
// create a new template object
$template = new PHPTAL('components/epayroll/new/employeeView.xhtml');
require_once("employeeClass.php");
$people = array();
$people[] = new Person("foo");
// put some data into the template context
$template->title = 'The title value';
$template->people = $people;
// execute the template
try {
echo $template->execute();
}
catch (Exception $e){
echo $e;
}
2.empview.xhtml
<td> <tal:block metal:define-macro="text"> <input name="${name}"
tal:attributes="id id | nothing" type="text" value="person/name"
/> </tal:block> </td>
3.empclass.php
class Person {
public $name;
function Person($name){
$this->name = $name;
}
}
请帮助我采取步骤。
感谢您的宝贵回复
在employeeView.xhtml
中您需要迭代人:
<div tal:repeat="person people">
<!-- you can use person here -->
</div>
如果要调用宏,则:
<div tal:repeat="person people">
<div metal:use-macro="text" />
</div>
,如果您希望将数组键用作ID,则可能还可以将tal:define="id repeat/person/key"
之类的东西添加到内部<div>
。
和设置<input>
的值:
<input value="${person/name}">
这是:
的短手<input tal:attributes="value person/name">