Custom PHP MVC Framework - Creating Multilevel Navigation & Commenting Systems, etc

I’m trying not to break the main MVC architecture of my custom PHP MVC framework when generating multi-level navigation menus and a commenting system.

In which part of the MVC files should I create recursive functions to generate multilevel navigation menus or if I wanted to generate a commenting system that requires recursion?

Here’s part of the main MVC folder/path structure that I’m currently using:

This is the Core Model “Core/Model.php” file:

<?php
class Model {
    private $host = DBHOST;
    private $user = UN;
    private $pw = PW;
    private $dbname = DBNAME;
    
    private $dbh;
    private $stmt;
    private $error;

    public function __construct() {
        $dsn = "mysql:host=$this->host; dbname=$this->dbname";
        $options = [
            PDO::ATTR_PERSISTENT => true,
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
        ];

        try {
            $this->dbh = new PDO($dsn, $this->user, $this->pw, $options);
            #echo 'Successfully connected to the database using PDO!';
        } catch(PDOException $e) {
            $this->error = $e->getMessage();
            echo $this->error;
        }
    }

    public function query($sql){
        $this->stmt = $this->dbh->prepare($sql);
    }


    #Bind the values: *NOTE: Bind only when selecting by passing a property argument through a param.
    public function bind($param, $value, $type = null){
        if(is_null($type)){
            switch(true){
                case is_int($value):
                    $type = PDO::PARAM_INT;
                    break;
                case is_bool($value):
                    $type = PDO::PARAM_BOOL;
                    break;
                case is_null($value):
                    $type = PDO::PARAM_NULL;
                    break;
                default:
                    $type = PDO::PARAM_STR;
            }
            
        }
        $this->stmt->bindValue($param, $value, $type);
    }
    

    public function execute(){
        return $this->stmt->execute();
    }

    public function resultSet(){
        $this->execute();
        return $this->stmt->fetchAll(PDO::FETCH_OBJ);
    }

    public function single(){
        $this->execute();
        return $this->stmt->fetch(PDO::FETCH_OBJ);
    }

}

Here’s the Models directory “models/PagesModel.php” file:

<?php

class PagesModel {

    private $db;

    public function __construct(){

        $this->db = new Model();

    }

  
    #Top Navigation:

    public function top_nav(){

        $this->db->query('SELECT * FROM navs WHERE level = 1');

        return $this->db->resultSet();

    }

}

This is the controllers “controllers/Pages.php” file:

<?php

class Pages extends Controller {

    #Load the homepage model data and view:

    public function homepage(){

        $topnav = $this->model('PagesModel')->top_nav();


        // Call a view helper function to render multi-level menu

       


        $data = [

            'topnav' => $topnav,

           

        ];


        $this->view('pages/index', $data);

    }


}

This is the Core “core/Controller.php” file:

<?php
class Controller {
    public function model($model){
        if(file_exists('../app/models/'. $model . '.php')){
            require_once '../app/models/'. $model . '.php';
            return new $model();
        }
    }

    public function view($view, $data = []){
        if(file_exists('../app/views/' . $view . '.php')){
            require_once '../app/views/' . $view . '.php';
        } else {
            die('View file does NOT exist.');
        }
    }
}

I can share more of the framework files if needed, but what I’m asking is how would I implement the multilevel navigation menus that require recursive functions without breaking the main architecture of the overall framework? Is this supposed to be done in the helper files or which would you recommend I try? Any support is appreciated.