[英]I don't understand where beginChildren, endChildren functions are called
I'm a novice, trying to learn PHP (and object-oriented programming in general). 我是一个新手,尝试学习PHP(以及一般的面向对象编程)。 I've tried to follow the threads, but I can't see where the functions current(), beginChildren() and endChildren() are getting called.
我尝试遵循线程,但是看不到函数current(),beginChildren()和endChildren()的调用位置。 Many thanks in advance if anyone can let me know where these get called, and equally importantly, how to I search this out by myself next time?
如果有人可以让我知道在哪里打电话,我要在此先多谢。同样重要的是,下次我该如何自行搜索?
class TableRows extends RecursiveIteratorIterator {
function __construct($it) {
parent::__construct($it, self::LEAVES_ONLY);
}
function current() {
return "<td style='width:150px;border:1px solid black;'>" . parent::current(). "</td>";
}
function beginChildren() {
echo "<tr>";
}
function endChildren() {
echo "</tr>" . "\n";
}
}
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "testDBPDO";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT id, firstname, lastname FROM MyGuests");
$stmt->execute();
// set the resulting array to associative
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
echo $v;
}
}
in answer to " how to I search this out by myself next time? " 回答“我下次如何自己搜索?”
I saw your 'TableRows' class extends from 'RecursiveIteratorIterator', so I have googled 'RecursiveIteratorIterator' 我看到您的'TableRows'类是从'RecursiveIteratorIterator'扩展而来的,所以我用Google搜索'RecursiveIteratorIterator'
then I have found the refernce of it : PHP: RecursiveIteratorIterator - Manual 然后我找到了它的引用: PHP:RecursiveIteratorIterator-Manual
there I have found some usefule information about your issue 那里我找到了一些有关您的问题的有用信息
another useful link in stackoverflow : How does RecursiveIteratorIterator work in PHP? stackoverflow中的另一个有用链接: RecursiveIteratorIterator如何在PHP中工作?
have a good learning time 玩得开心
" beginChildren " in this case is a function that acts within a nested list, to show in this specific case an html element. 在这种情况下,“ beginChildren ”是一个在嵌套列表中起作用的函数,用于在这种情况下显示html元素。 I am referring to a nested list because the HTML element that represents a list within a table is opened with 'tr' to show the current that it is inside a cell 'td' and then closes with the ' endChildren ' and its respective /tr.
我指的是一个嵌套列表,因为代表表中列表的HTML元素以“ tr”打开,以显示当前位于单元格“ td”内的当前内容,然后以“ endChildren ”及其相应的/ tr关闭。 It is a function that acts as a complement to nested lists;
它是对嵌套列表的补充。 very used in HTML that acts a lot with markers.
非常用在HTML中,它与标记作用很大。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.