2

我是 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;
}
}

请帮助我执行此操作的步骤。

感谢您的宝贵回复

4

1 回答 1

1

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">
于 2014-01-24T23:29:51.643 回答