简体   繁体   中英

Call to Member function on Array

So I'm utilizing a for each to try to generate a menu dynamically from a MySQL database. Because there's more than one it will always return an array. I use multiple files to generate the menu. I use a class to create the menu

class menu extends db{
       public function LoadMainMenu() {
       global $db;
       $query = <<<SQL
       SELECT id,name
       FROM menu
       WHERE enabled = :active
       AND location = :mainmenu
SQL;
       $resource = $db->sitedb->prepare( $query );
       $resource->execute( array(
       ':active'    => '1',
       ':mainmenu'  => '1',
));
foreach($resource as $row){
       echo '<li><a href="viewPage?pageid='.$row['id'].'">'.$row['name'].'</a></li>';
   }
}
$menu = new menu();

My next file is my base.class.php file

function LoadMainMenu() {
global $menu;
$menu->LoadMainMenu();
}

Then I have my index.php file within my theme settings where I have it called

<ul class='topmenu'>
<?php LoadMainMenu(); ?>
</ul>

It then gives me the error that it's a call to a member function on an array on base.class.php; If anymore code would help please let me know.

Not Really an end all cure all, but it works. I added it within the db.class.php and then just added global $db and then called $db->GetMainMenu() within the main index.php Template and it seems to have worked. Other than that I'm not sure what else to do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM