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 6687771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:19:40+00:00 2026-05-26T05:19:40+00:00

I am creating a custom MVC framework. I verrrrry loosely modeled it after the

  • 0

I am creating a custom MVC framework.

I verrrrry loosely modeled it after the codeIgniter framework, but it’s ground-up custom for the most part.

I’m at the point where I have URL’s routing to the appropriate controller actions, but I’m stuck at the point where I generate a view that can utilize data generated by the controller.

I have views defined (static HTML with inline php ready to populate dynamic data), and I have the destructor of my base controller require()’ing the view in order to populate the browser with the view… here’s the code:

public function __destruct()
{
    if ($this->bSuppressView === false)
    {
        require(APP_PATH.'views/layout/header.php');
        require(APP_PATH.'views/'.$this->sController.'/view.'.$this->sController.'.'.$this->sAction.'.php');
        require(APP_PATH.'views/layout/footer.php');
    }
}

Basically, when the controller is done executing, the teardown process of the base controller will then include the global header view, the controller’s action’s view, and then the global footer view, which should populate the webpage with everything for the URL that was requested…

HOWEVER, I cannot access any globally defined variables from the embedded php in the view code. In my bootstrap class, I define a bunch of local variables such as my config variable, etc., but the view seems to consider those variables undefined. Additionally, i’m unsure how to allow the view to access data that the controller may have generated. Where do I “stick” it to make it available to the view?

Let me know if this isn’t clear, and i’ll update.
Thanks!

UPDATE: I’ve discovered that while doing it this way, the “environment” of the views is within the controller object, which, as far as I can tell is a great thing! I don’t have to propogate anything anywhere but in the controller, and I can use “$this->” in the views to get access to anything public or private from within the controller class!!!

That leaves the question: is this “normally” how it’s done in MVC? What’s the BEST way to propogate a view? I think this will suit my purposes, and I will post back if I discover a limitation to just treating the embedded view php as “within the scope of the calling controller”…

  • 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-26T05:19:40+00:00Added an answer on May 26, 2026 at 5:19 am

    The way this is generally done, is that the view is actually an object. You pass that object you’re variables, and that view object takes the template you gave it, includes it so that it’s in the current scope, and grab the output into a variable using output buffering.

    To give you a basic idea:

    // controller object
    $this->set('key','val');
    $this->render('mytemplate');
    
    // controller base class
    $view = new View;
    $view->setData($this->getData());
    
    // view class
    class View {
    ....
    function render() {
        ob_start();
        include $this->resolveTemplate();
        $out = ob_get_contents();
    
        ob_end_clean();
    
        return $out;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a custom MVC framework, but I'm stuck with some URL definitions in
I have an ASP.NET MVC 2 application in which I am creating a custom
I'm learning about creating custom routes in ASP.NET MVC and have hit a brick
I'm having problems creating MVC 3 T4 template. I have cleared the Custom Tool
I am creating my own helper in MVC. But the custom attributes are not
I am in the middle of creating my own custom MVC web framework for
I'm new to ASP.NET, C# and the MVC framework but have managed to build
I am creating a custom MVC style framework from scratch and am at the
I'm creating a custom MembershipProvider for an ASP.NET MVC website, and I was planning
Jython is great for creating custom data structures on need basis, but how to

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.