amr87 Posted November 9, 2011 Share Posted November 9, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/250787-mvc-and-oop-help/ Share on other sites More sharing options...
trq Posted November 9, 2011 Share Posted November 9, 2011 Your Controller is not the same 'type' as a Loader, and therefore should not extend it. Quote Link to comment https://forums.phpfreaks.com/topic/250787-mvc-and-oop-help/#findComment-1286796 Share on other sites More sharing options...
xyph Posted November 9, 2011 Share Posted November 9, 2011 On another note, before you dive into design patterns and OOP, you should get into the habit of properly formatting your code. http://en.wikipedia.org/wiki/Prettyprint#Code_formatting_and_beautification - see examples Quote Link to comment https://forums.phpfreaks.com/topic/250787-mvc-and-oop-help/#findComment-1286820 Share on other sites More sharing options...
amr87 Posted November 9, 2011 Author Share Posted November 9, 2011 2 replies and no answer for my question , please if u have a solution just post it and do not post comments and notes on my code , really funny staff Quote Link to comment https://forums.phpfreaks.com/topic/250787-mvc-and-oop-help/#findComment-1286830 Share on other sites More sharing options...
xyph Posted November 9, 2011 Share Posted November 9, 2011 Hey guys, I'm trying to follow a standardized approach to a design pattern, without following standardized syntax or applying the rules of the pattern. Really funny strategy. Quote Link to comment https://forums.phpfreaks.com/topic/250787-mvc-and-oop-help/#findComment-1286833 Share on other sites More sharing options...
amr87 Posted November 10, 2011 Author Share Posted November 10, 2011 xyph I solved the case , some investigation in the loader class of codeigniter framework helped me , tell me if u need the solutions it was all about the instance scope Quote Link to comment https://forums.phpfreaks.com/topic/250787-mvc-and-oop-help/#findComment-1286903 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.