get menu

Need Help?

i have this code to get menu




 public static function getMenu() {


        $data2 = array();


        $menu = PolicyAndProcedureMenu::find()

                ->all();




        foreach ($menu as $value => $models) {

            $row = array();

            $row['label'] = $models->label;

            $row['url'] = array($models->url);

            if (count(static::getMenu2(' =' . $models->id)) > 0) {

                $row['items'] = static::getMenu2(' =' . $models->id);

            }

            $data2[] = $row;

        }


        return $data2;

    }







  public static function getMenu2() {

        $data2 = array();

        $menu = PolicyAndProcedureMenu::find()

                ->all();


        foreach ($menu as $value => $models) {

            $row = array();

            $row['label'] = $models->label;

            $row['url'] = array($models->url);

            if (count(static::getMenu2(' =' . $models->id)) > 0)

                $row['items'] = static::getMenu2(' =' . $models->id);

            $data2[] = $row;

        }


        return $data2;

    }






no getting error, but Maximum execution time of 30 seconds exceeded.

In "getMenu()" method, you have to specify some condition that selects only the top level menu items.

And "getMenu2()" method should accept a filtering condition. The current one will fall into an endless recursive call.

thank sir.

my problem have been solved. :D

Increase your php max execution time also.

It doesn’t make sense for an endless loop.

And usually it’s not a very good idea to increase the php max execution time in order to work around the problem, IMO.