Jump to content

MVC and OOP Help


amr87

Recommended Posts

Hello Everyone ,

I`m trying to build MVC pattern using OOP PHP ,

please read the rest of the post to understand what I want exactly

 

This is the homepage controller which extends the main controller

 

<?php
class Home extends Controller {

function __construct () {

parent::__construct();

}



public function index () {

$data = array (
'name' => "Amr",
'age' =>24
);
$this->load->view("home_view",$data);
}

}

 

The Main Controller looks like this and extends loader class

<?php
class Controller extends Loader {
public $load;

function __construct(){
parent::__construct();
$this->load = new Loader();


}


?>


}

 

The Loader class which has the problem is look like that

 

<?php
class Loader  {

public $Error;

function __construct(){
$this->Error = new Error();
}

public function model($Modelname){
$this->$Modelname = $Modelname;
if (file_exists("models/".$Modelname.".php")){
require_once $Modelname . ".php";
$this->$Modelname = new $Modelname;


}else{
$this->Error->Not_found();
}
}

public function view($Viewname,$data=NULL){
if(is_array($data)){
extract($data);
}
if (file_exists("views/".$Viewname.".php")){
require_once $Viewname . ".php";
}else{
$this->Error->Not_found();
}
}

public function helper($helper) {

if (file_exists("helpers/".$helper.".php")){
require_once $helper . ".php";
$this->$helper = new $helper;
}else{
$this->Error->Not_found();
}
}


}
?>

what I need to do is to be able FROM HOMEPAGE Controller to do something like this

<?php
$this->load->model("someModel");
$this->someModel->someMethodInModel();
// and the same for helper
$this->load->helper("someHelper");
$this->someHelper->someMethodInHelper();

?>

 

can anyone help?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.