2

私は PHPTAL の初めてのユーザーで、PHPTAL を使用して入力ボックスに値を提供することができません。3 つのファイル 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>

useの値を設定するに<input>は:

<input value="${person/name}">

これは次の省略形です。

<input tal:attributes="value person/name">
于 2014-01-24T23:29:51.643 に答える