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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:14:04+00:00 2026-05-25T06:14:04+00:00

I have been working on my own library/framework for the learning experience for a

  • 0

I have been working on my own library/framework for the learning experience for a while. MVC is one of those things that took me a while to really understand but I do finally “Get it”.

Below is some sample code for a basic MVC setup in PHP. I think I am in the right direction so far, where I need a little help is down in the “Example controller” near the bottom, you will see where I can create a view, I just need to figure out how to best get my data from a model file into that controller class. Please help with example code if you can, hopefully I am making sense.

Also I am welcome to any comments/suggestions on any of the code

Abstract Controller class…

/**
 * MVC Example Project
 */


/**
* Extend this class with your Controllers
* Reference to the model wrapper / loader functions via $this->model
* Reference to the view functions via $this->view
*/
abstract class Core_Controller {
    protected $view;
    protected $model;

    function __construct($dependencyContainer){
        $this->view = new Core_View();
        //$this->view = $dependencyContainer->get(view);


    }

}

Abstract Model class…

/**
* Extend this class with your models and reference to the database object via $this->$db
*/
abstract class Core_Model {
    protected $db;
    protected $session;

    function __construct($dependencyContainer) {
        $this->db = $dependencyContainer->get(database);
        $this->session = $dependencyContainer->get(session);
    }

}

View class, might make it abstract as well…

class Core_View {

    protected $data;

    # Load a view file (views/$view.php);
    # $param data this gets extracted and be thus be used inside the view
    # When loading another view from inside the view file the data is 'cached' so you
    # don't have to pass them again
    public function load($view,$data = null) {

        if($data) {
            $this->data = $data;
            extract($data);
        } elseif($this->data != null) {
                extract($this->data);
        }

        require(APP_PATH . "Views/$view.php");
    }

    public function set($data = null) {

        if($data) {
            $this->data = $data;
            extract($data);
        } elseif($this->data != null) {
                extract($this->data);
        }

    }
}

Example putting it together…

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

    public function profile()
    {
        $profileData = array();
        $profileData = //GET from Model

        $this->view->load('userProfile', $profileData);
    }
}
?>
  • 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-25T06:14:05+00:00Added an answer on May 25, 2026 at 6:14 am

    Will you use a Data access layer (DAL) / Object-relational mapping (ORM)? Take a look at Zend_Db, Doctrine or Propel

    I’d say that you’re missing the part of the application that manipulate your models. It could be your controller, but isn’t a good practice. So we need a model mapper.

    The best way to get model data from your controller is simply calling it. But generally we use a kind of "pointer" which knows how to populate your object model. This pointer is called "Mappers" (Data Mapper Pattern):

    $MyModelMapper = new MyModelMapper();
    $Profile = $MyModelMapper->getProfileById($id); // return Core_Model.
    

    This function will perform a database query and will populate one specific model with the data. You could also get an array of objects for a "list" action for example.

    Then you’ll pass this model to your view.

    I think you should take a look at the Zend Framewok quick start. It will give you some ideas.

    See this question too: What's the difference between DAO and Data Mapper

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

Sidebar

Related Questions

For a couple of years I have been working on my own lightweight MVC
I've been working on my own personal JavaScript library for a while now, and
I have been working with a string[] array in C# that gets returned from
I have been working on some legacy C++ code that uses variable length structures
I have been working on a wrapper for a COM object that can only
This is a weird one. On and off as I have been working on
I have been working on a comparatively large system on my own, and it's
I have been working on some of the projects of my own and dont
I have been working with System.DirectoryServices for a while in a project involving Active
I've been working on my own javascript library, kis-js. I recently converted it 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.