1
<?php
class getCatlist
{
function catList()
{
global $db;
try {
$stmt2 = $db->query("SELECT c.id, c.name, c.slug, c.parent, COUNT(b.catID) AS Total FROM categories c LEFT JOIN blog_post_cats b ON b.catID = c.id GROUP BY c.id HAVING Total > 0");
$row_count = $stmt2->rowCount();
if ($row_count >= 0) {
$rows = $stmt2->fetchAll(PDO::FETCH_ASSOC);
}
} catch (PDOException $e) {
echo $e->getMessage();
}
$items = $rows;
$id = '';
echo "<ul>";
foreach ($items as $item) {
if ($item['parent'] == 0) {
echo "<li><a href='category-".$item['slug']."'>".$item['name']." (".$item['Total'].")</a>";
$id = $item['id'];
sub($items, $id);
echo "</li>";
}
}
echo "</ul>";
}
function sub($items, $id){
foreach ($items as $item) {
if ($item['parent'] == $id) {
echo "<ul>";
echo "<li><a href='category-".$item['slug']."'>".$item['name']." (".$item['Total'].")</a></li>";
sub($items, $item['id']);
echo "</ul>";
}
}
}
}
?>
我调用这个类与这些function catList()
和功能sub($items, $id)
调用未定义功能类
与:
<?php
$cat = new getCatlist();
$cat->catList();
$cat->sub();
?>
但服务器给我这个错误:调用未定义的函数子()。那么我的代码有什么问题?我想念什么?以及如何定义这个:function sub()。
我试过并从类的东西搜索这种调用方法,但我没有解决我的问题。所以我希望我在这里找到解决方案。谢谢。
仍不明确的功能子()\t 我想你的解决方案:我认为它会工作,但:缺少参数1 getCatlist ::子()并为getCatlist :: sub()缺少参数2。那么现在呢? –
那个错误信息很清楚不是吗? '$ cat-> sub()'不包含任何参数,但方法签名**需要**两个参数。 – HPierce
所以它必须是$ cat-> sub($ items,$ id)是不是? –