0

这是我的功能。使用 Yii 固件。

public function generateMenu($type, $class = "", $curl, $parent = 0)
{
    switch ($type) {
        case 1:
            //LEFT MENU
            $html = "<ul $class>";
            if ($parent == 0 && $type == 0)
                $html .= '<li>
                                <div class="sidebar-toggler hidden-phone"></div>
                             </li>';
            $criteria        = new CDbCriteria();
            $criteria->order = "sort ASC";
            $criteria->compare("menuType", $type);
            $criteria->compare("parent", 0);
            $bu      = Yii::app()->baseUrl;
            $results = AdminMenu::model()->findAll($criteria);
            if ($results) {
                $i = 1;
                foreach ($results as $result) {
                    $liClass = "";
                    if ($i == 1 && $parent == 0)
                        $liClass = "start";
                    else if ($i == count($results) && $parent == 0)
                        $liClass = "last";
                    $criteria        = new CDbCriteria();
                    $criteria->order = "sort ASC";
                    $criteria->compare("parent", $result->id);
                    $children = AdminMenu::model()->count($criteria);

                    $active = $this->checkIfActive($result->url, $curl);

                    $liClass .= ($active) ? " active" : "";

                    $html .= "<li class='$liClass'>
                         <a href='";
                    $html .= ($children > 0) ? "javascript::" : $result->url;
                    $html .= "'>";
                    $html .= (is_null($result->icon)) ? "" : "<i class='$result->icon' ></i>";
                    $html .= "< span class='title' >" . $result->title . " </span >";
                    $html .= ($active) ? "<span class='selected'></span>" : "";
                    $html .= "</a>";
                    if ($children > 0) {
                        $html .= $this->generateMenu($type, "", $curl, $result->id);
                    }
                    $html .= "</li>";
                }
                $html .= "</ul>";
            }
            return $html;
            break;
    }


}

像这样调用:$nav->generateMenu(1, "page-sidebar-menu", Yii::app()->request->url, 0);

PHP 在函数内部的某个地方进入无限循环。我究竟做错了什么?

数据库:

4

1 回答 1

2

尝试

$criteria->compare("parent", $parent);

代替

 $criteria->compare("parent", 0);
于 2013-09-28T15:10:16.693 回答