Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6540169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:56:44+00:00 2026-05-25T10:56:44+00:00

I am working on my own MVC framework. Below is an example controller I

  • 0

I am working on my own MVC framework. Below is an example controller I have so far.

I have a way of loading models into my controller and also view files.

I am wanting to also have different template options for my site. My template will just be a page layout that inserts the views that are created from my controller into the middle of my template file.

/**
 * Example Controller
 */
class User_Controller extends Core_Controller {

    // domain.com/user/id-53463463
    function profile($userId)
    {
        // load a Model
        $this->loadModel('profile');  

        //GET data from a Model
        $profileData = $this->profile_model->getProfile($userId);

        // load view file and pass the Model data into it
        $this->view->load('userProfile', $profileData);
    }

}

Here is a basic idea of the template file…

DefaultLayout.php

<!doctype html>
<html lang="en">
<head>
</head>
<body>



Is the controller has data set for the sidebar variable, then we will load the sidebar and the content
<?php if( ! empty($sidebar)) { ?>

<?php print $content; ?>

<?php print $sidebar; ?>


If no sidebar is set, then we will just load the content
<?php } else { ?>

<?php print $content; ?>

<?php } ?>

</body>
</html>

Another Template without any header, footer, anything else, can be used for AJAX calls

EmptyLayout.php

<?php
$content
?>

I am looking for ideas on how I can load my main template file and then include and view files into the content area of my main layout file?

In the sample layout file, you can see that the content area has a variable called $content. I am not sure how I can populate that with the views content, to be inserted into my main layout template. If you have any ideas, please post sample

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:56:44+00:00Added an answer on May 25, 2026 at 10:56 am

    Something a little bit like

    function loadView ($strViewPath, $arrayOfData)
    {
    // This makes $arrayOfData['content'] turn into $content
    extract($arrayOfData);
    
    // Require the file
    ob_start();
    require($strViewPath);
    
    // Return the string
    $strView = ob_get_contents();
    ob_end_clean();
    return $strView;
    }
    

    Then use with

    $sidebarView = loadView('sidebar.php', array('stuff' => 'for', 'sidebar' => 'only');
    $mainView = loadView('main.php', array('content' => 'hello',, 'sidebar' => $sidebarView);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have my own hand-rolled PHP MVC framework for some projects that I'm working
If we have developed our own ORM framework and the framework is working fine
I am currently working on my own implementation of a MVC framework. I would
So I'm working on my own little MVC framework as a learning exercise. It's
I'm working with the MVC example here , and have bypassed the PhoneGap contacts
For a couple of years I have been working on my own lightweight MVC
I have been working on my own library/framework for the learning experience for a
I'm working through SICP on my own, so I don't have an instructor to
I'm currently working on my own PHP Framework, and I need some help figuring
I'm working on an ASP.NET MVC site which will have a database. While I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.