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

  • SEARCH
  • Home
  • 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 9245563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:17:38+00:00 2026-06-18T09:17:38+00:00

I have a simple controller file StudentController.php <?php $data = array(); $data[firstName] = $_GET[firstName];

  • 0

I have a simple controller file StudentController.php

<?php

$data = array();
$data["firstName"] = $_GET["firstName"];

loadView("StudentView.php", $data);

?>

I have a even simpler view file called StudentView.php

<?php

echo $firstName;

?>

I have absolutely no idea how to implement loadView($view, $data) function. I want variables from $data in controller became available in view ($data["foo"] from controller became $foo in view)

I want achieve what is very easy to do in CodeIgniter but I have no idea how it is implemented. I tried to look into Controller.php and Loader.php in source files, but it was too messy for me to understand.

I don’t want to use CodeIgniter or any other framework, I want to natively do in PHP.

  • 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-06-18T09:17:39+00:00Added an answer on June 18, 2026 at 9:17 am

    If you’re going to be building a large website to be used by the general public, a framework is generally a good idea for multiple reasons:

    • Properly unit tested – generally speaking, you can be confident that the core of your website is functioning as it’s intended to
    • Community support – have questions and you can easily get answers; generally these frameworks are open sourced and usually actively developed by the PHP community
    • Secure – Framework developers are, well, framework developers; and they have been trained to write code with security as a top priority

    However, this question has nothing to do with frameworks vs not, so I’ll answer the question you asked with a very simple function:

    function loadView($view, $data) {
        extract($data);
        ob_start();
        require_once $view;
        $contents = ob_get_contents();
        ob_end_clean();
        return $contents;
    }
    

    You can chose to return the contents or print them directly, but that function should do what you need. I’m making no guarantees about the security of this code, and I have obviously done no error checking. But it should serve as a great foundation to get you started.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple RootView Controller ->Detail View Controller, to display a list
I have a simple unsubscribe function in my Unsubscribed controller. if ($this->Unsubscribe->save($this->data['Unsubscribes'])) { //
I have a simple controller named AjaxController, <?php class AjaxController extends Zend_Controller_Action { public
I have build a simple MVC library. There is a front controller. htaccess file
I have imported the pdf.h file in my view controller class and tried calling
I have the following data flow for a simple login form. User access controller
I'm a bit confused here. I have a simple controller which loads a view.
I have a simple search form (site/search.php) to send search string to controller and
I have a simple application, in which there is a view controller which is
I have this simple code in my user_controller.rb file #listing all users def index

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.