A basic MVC with routing and login system in PHP

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
0
down vote

favorite












I started working in PHP and I wrote several things before I noticed that I'm not sure if I'm doing DI right. So, I need someone to review an example of my code and tell me what I did wrong, and I'm sure I did something wrong.



First a note, I am well aware of the DIC, however I decided not to go that way for this small project. The point of it is to get a firm footing in PHP, MVC and OOP before going onward to frameworks and their DIC ways.



The following code is just a login form and all the backend that goes with it.



The login form:



<form action="<?php echo URL; ?>login/user_login" method="POST">
<div class="form-inline ">
<label for="exampleInputPassword1" class="col-form-label col-form-label-sm"></label>
<input type="text" class="form-control form-control-sm" name="username" id="exampleInputPassword1" placeholder="Username">


<label for="exampleInputPassword2"></label>
<input type="password" class="form-control form-control-sm" name="password" id="exampleInputPassword2" placeholder="Password">


<button type="submit" name="submit_login" class="btn btn-primary btn-sm">Login</button>

</div>
</form>


bootstrap



<?php

class Bootstrap

protected $controller = 'index';

protected $method = 'index';

protected $paramaters = ;

protected $container;


//_________________
public function __construct()

session_start();

$url = $this->parseURL();

//_______________________________________________________________________

//_______________________________________________________________________
if(file_exists('controllers/'.$url[0].'.php'))
$this->controller = $url[0];
unset($url[0]);

//_______________________________________________________________________
require_once 'controllers/'.$this->controller.'.php';
$this->contr_name = $this->controller;


$this->container = new Controllers_container;
$this->controller = new $this->controller($this->container);



//on declaring new object pass in tha paramaters??
//DIC and AUTOLOADER

//_______________________________________________________________________
if (isset($url[1]))
if(method_exists($this->controller, $url[1]))
$this->method = $url[1];
unset($url[1]);


//_______________________________________________________________________




//_______________________________________________________________________
$this->paramaters = $url ? array_values($url):;

call_user_func([$this->controller,$this->method],$this->paramaters);


public function parseURL()
if(isset($_GET['url']))
$url = explode('/', filter_var(rtrim($_GET['url'],'/'), FILTER_SANITIZE_URL));
return $url;









login controller:



<?php

class Login implements controllerInterface

protected $name = 'login';

protected $container;

protected $model_instance;

protected $data = ;

public function __construct(container $container)
$this->input = $container->loadInputArray();
$this->modelServices = $container->loadServices();
$this->model_instance = $container->loadModel($this->name , $this->input , $this->modelServices);


public function index()
$this->view->render($this->path, $this->data,$this->error);


public function user_login()
$this->model_instance->user_login($this->input);


public function user_logout()
$this->model_instance->user_logout();






login model:



<?php

class loginModel implements modelInterface

protected $name = 'login';

protected $model_lib;

protected $dbc;

protected $view;

protected $session;

protected $path;

protected $error;

protected $input;

protected $data_wrapper;

protected $data = ;

function __construct($array , modelServices $services )

$this->modelServices = $services;
$this->dbc= $this->modelServices->loadDatabase();
$this->model_lib= $this->modelServices->loadQuerys($this->dbc);
$this->data_wrapper= $this->modelServices->loadDataWrapper();
$this->view = $this->modelServices->loadView($this->name);
$this->session = $this->modelServices->loadSessions($this->name);
$this->input = $array;


public function user_login($input)
//print_r ($input->postArray);
if (!isset($input->postArray['submit_login']))
//$this->data = 'NO SUBMIT SENT';
$this->error = 'generic_error';
$this->view->render($this->path,$this->data_wrapper, $this->error);

else
if (empty($input->postArray['username'])


//$user_data = $this->model_lib->find_user_by_id($this->dbc);
//$this->view->render($user_data);




public function user_logout()

if (!isset($_POST['submit_logout']))
//$this->data = 'no submit posted';
$this->render->view($this->path,$this->data,$this->error);
else

$note = $this->session -> destroy_session();
if($note == true)
//$this->data = 'Loged out';
//header ('Location: index');
//$this->path = 'index';
$this->view->render($this->path,$this->data,$this->error);
else
//$this->data= 'could not destroy session';
$this->view->render($this->path,$this->data,$this->error);








Now a note: I used to create all dependencies before hand and then just pass them along.. however that seemed ineficient. so i split the dependency "generating" into two "services" classes - >controllers_container and modelServices (i am aware of the naming, and i will change that, sorry for presenting as is) and pass those, one to controllers and the other to models, and use them to call the rest. (This is the part I believe to be wrong).



here they are:



<?php


class Controllers_container implements container
protected $model_instance;

protected $dataWrapper_instance;

protected $inputArray_instance;

protected $modelServices_instance;

public function __construct()

public function __destruct()
$this->model_instance = NULL;


public function loadModel($name , inputCollector $input , modelServices $services)

require_once 'models/'.$name.'Model.php';
$this->model_instance = $name.'Model';
//--------------------------------
$this->model_instance = new $this->model_instance($input , $services);
return $this->model_instance;


public function loadServices()

$this->modelServices_instance = new modelServices;
return $this->modelServices_instance;



public function loadInputArray()
$this->inputArray_instance = new inputCollector;
return $this->inputArray_instance;







<?php


class Controllers_container implements container
protected $model_instance;

protected $dataWrapper_instance;

protected $inputArray_instance;

protected $modelServices_instance;

public function __construct()

public function __destruct()
$this->model_instance = NULL;


public function loadModel($name , inputCollector $input , modelServices $services)

require_once 'models/'.$name.'Model.php';
$this->model_instance = $name.'Model';
//--------------------------------
$this->model_instance = new $this->model_instance($input , $services);
return $this->model_instance;


public function loadServices()

$this->modelServices_instance = new modelServices;
return $this->modelServices_instance;



public function loadInputArray()
$this->inputArray_instance = new inputCollector;
return $this->inputArray_instance;






and the view:



<?php


class Controllers_container implements container
protected $model_instance;

protected $dataWrapper_instance;

protected $inputArray_instance;

protected $modelServices_instance;

public function __construct()

public function __destruct()
$this->model_instance = NULL;


public function loadModel($name , inputCollector $input , modelServices $services)

require_once 'models/'.$name.'Model.php';
$this->model_instance = $name.'Model';
//--------------------------------
$this->model_instance = new $this->model_instance($input , $services);
return $this->model_instance;


public function loadServices()

$this->modelServices_instance = new modelServices;
return $this->modelServices_instance;



public function loadInputArray()
$this->inputArray_instance = new inputCollector;
return $this->inputArray_instance;






PS. I know the functionality of classes can be improved (and it will be). My main problem is the DI and whether I am adhering to the MVC and SOLID principles.







share|improve this question





















  • Welcome to Code Review! Does the code currently work as intended?
    – Mast
    Jul 18 at 16:34










  • Hi, and ty. Yes, it works perfectly. However, i would still like to know if i adhere to the principles.
    – BlackBit
    Jul 18 at 16:37
















up vote
0
down vote

favorite












I started working in PHP and I wrote several things before I noticed that I'm not sure if I'm doing DI right. So, I need someone to review an example of my code and tell me what I did wrong, and I'm sure I did something wrong.



First a note, I am well aware of the DIC, however I decided not to go that way for this small project. The point of it is to get a firm footing in PHP, MVC and OOP before going onward to frameworks and their DIC ways.



The following code is just a login form and all the backend that goes with it.



The login form:



<form action="<?php echo URL; ?>login/user_login" method="POST">
<div class="form-inline ">
<label for="exampleInputPassword1" class="col-form-label col-form-label-sm"></label>
<input type="text" class="form-control form-control-sm" name="username" id="exampleInputPassword1" placeholder="Username">


<label for="exampleInputPassword2"></label>
<input type="password" class="form-control form-control-sm" name="password" id="exampleInputPassword2" placeholder="Password">


<button type="submit" name="submit_login" class="btn btn-primary btn-sm">Login</button>

</div>
</form>


bootstrap



<?php

class Bootstrap

protected $controller = 'index';

protected $method = 'index';

protected $paramaters = ;

protected $container;


//_________________
public function __construct()

session_start();

$url = $this->parseURL();

//_______________________________________________________________________

//_______________________________________________________________________
if(file_exists('controllers/'.$url[0].'.php'))
$this->controller = $url[0];
unset($url[0]);

//_______________________________________________________________________
require_once 'controllers/'.$this->controller.'.php';
$this->contr_name = $this->controller;


$this->container = new Controllers_container;
$this->controller = new $this->controller($this->container);



//on declaring new object pass in tha paramaters??
//DIC and AUTOLOADER

//_______________________________________________________________________
if (isset($url[1]))
if(method_exists($this->controller, $url[1]))
$this->method = $url[1];
unset($url[1]);


//_______________________________________________________________________




//_______________________________________________________________________
$this->paramaters = $url ? array_values($url):;

call_user_func([$this->controller,$this->method],$this->paramaters);


public function parseURL()
if(isset($_GET['url']))
$url = explode('/', filter_var(rtrim($_GET['url'],'/'), FILTER_SANITIZE_URL));
return $url;









login controller:



<?php

class Login implements controllerInterface

protected $name = 'login';

protected $container;

protected $model_instance;

protected $data = ;

public function __construct(container $container)
$this->input = $container->loadInputArray();
$this->modelServices = $container->loadServices();
$this->model_instance = $container->loadModel($this->name , $this->input , $this->modelServices);


public function index()
$this->view->render($this->path, $this->data,$this->error);


public function user_login()
$this->model_instance->user_login($this->input);


public function user_logout()
$this->model_instance->user_logout();






login model:



<?php

class loginModel implements modelInterface

protected $name = 'login';

protected $model_lib;

protected $dbc;

protected $view;

protected $session;

protected $path;

protected $error;

protected $input;

protected $data_wrapper;

protected $data = ;

function __construct($array , modelServices $services )

$this->modelServices = $services;
$this->dbc= $this->modelServices->loadDatabase();
$this->model_lib= $this->modelServices->loadQuerys($this->dbc);
$this->data_wrapper= $this->modelServices->loadDataWrapper();
$this->view = $this->modelServices->loadView($this->name);
$this->session = $this->modelServices->loadSessions($this->name);
$this->input = $array;


public function user_login($input)
//print_r ($input->postArray);
if (!isset($input->postArray['submit_login']))
//$this->data = 'NO SUBMIT SENT';
$this->error = 'generic_error';
$this->view->render($this->path,$this->data_wrapper, $this->error);

else
if (empty($input->postArray['username'])


//$user_data = $this->model_lib->find_user_by_id($this->dbc);
//$this->view->render($user_data);




public function user_logout()

if (!isset($_POST['submit_logout']))
//$this->data = 'no submit posted';
$this->render->view($this->path,$this->data,$this->error);
else

$note = $this->session -> destroy_session();
if($note == true)
//$this->data = 'Loged out';
//header ('Location: index');
//$this->path = 'index';
$this->view->render($this->path,$this->data,$this->error);
else
//$this->data= 'could not destroy session';
$this->view->render($this->path,$this->data,$this->error);








Now a note: I used to create all dependencies before hand and then just pass them along.. however that seemed ineficient. so i split the dependency "generating" into two "services" classes - >controllers_container and modelServices (i am aware of the naming, and i will change that, sorry for presenting as is) and pass those, one to controllers and the other to models, and use them to call the rest. (This is the part I believe to be wrong).



here they are:



<?php


class Controllers_container implements container
protected $model_instance;

protected $dataWrapper_instance;

protected $inputArray_instance;

protected $modelServices_instance;

public function __construct()

public function __destruct()
$this->model_instance = NULL;


public function loadModel($name , inputCollector $input , modelServices $services)

require_once 'models/'.$name.'Model.php';
$this->model_instance = $name.'Model';
//--------------------------------
$this->model_instance = new $this->model_instance($input , $services);
return $this->model_instance;


public function loadServices()

$this->modelServices_instance = new modelServices;
return $this->modelServices_instance;



public function loadInputArray()
$this->inputArray_instance = new inputCollector;
return $this->inputArray_instance;







<?php


class Controllers_container implements container
protected $model_instance;

protected $dataWrapper_instance;

protected $inputArray_instance;

protected $modelServices_instance;

public function __construct()

public function __destruct()
$this->model_instance = NULL;


public function loadModel($name , inputCollector $input , modelServices $services)

require_once 'models/'.$name.'Model.php';
$this->model_instance = $name.'Model';
//--------------------------------
$this->model_instance = new $this->model_instance($input , $services);
return $this->model_instance;


public function loadServices()

$this->modelServices_instance = new modelServices;
return $this->modelServices_instance;



public function loadInputArray()
$this->inputArray_instance = new inputCollector;
return $this->inputArray_instance;






and the view:



<?php


class Controllers_container implements container
protected $model_instance;

protected $dataWrapper_instance;

protected $inputArray_instance;

protected $modelServices_instance;

public function __construct()

public function __destruct()
$this->model_instance = NULL;


public function loadModel($name , inputCollector $input , modelServices $services)

require_once 'models/'.$name.'Model.php';
$this->model_instance = $name.'Model';
//--------------------------------
$this->model_instance = new $this->model_instance($input , $services);
return $this->model_instance;


public function loadServices()

$this->modelServices_instance = new modelServices;
return $this->modelServices_instance;



public function loadInputArray()
$this->inputArray_instance = new inputCollector;
return $this->inputArray_instance;






PS. I know the functionality of classes can be improved (and it will be). My main problem is the DI and whether I am adhering to the MVC and SOLID principles.







share|improve this question





















  • Welcome to Code Review! Does the code currently work as intended?
    – Mast
    Jul 18 at 16:34










  • Hi, and ty. Yes, it works perfectly. However, i would still like to know if i adhere to the principles.
    – BlackBit
    Jul 18 at 16:37












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I started working in PHP and I wrote several things before I noticed that I'm not sure if I'm doing DI right. So, I need someone to review an example of my code and tell me what I did wrong, and I'm sure I did something wrong.



First a note, I am well aware of the DIC, however I decided not to go that way for this small project. The point of it is to get a firm footing in PHP, MVC and OOP before going onward to frameworks and their DIC ways.



The following code is just a login form and all the backend that goes with it.



The login form:



<form action="<?php echo URL; ?>login/user_login" method="POST">
<div class="form-inline ">
<label for="exampleInputPassword1" class="col-form-label col-form-label-sm"></label>
<input type="text" class="form-control form-control-sm" name="username" id="exampleInputPassword1" placeholder="Username">


<label for="exampleInputPassword2"></label>
<input type="password" class="form-control form-control-sm" name="password" id="exampleInputPassword2" placeholder="Password">


<button type="submit" name="submit_login" class="btn btn-primary btn-sm">Login</button>

</div>
</form>


bootstrap



<?php

class Bootstrap

protected $controller = 'index';

protected $method = 'index';

protected $paramaters = ;

protected $container;


//_________________
public function __construct()

session_start();

$url = $this->parseURL();

//_______________________________________________________________________

//_______________________________________________________________________
if(file_exists('controllers/'.$url[0].'.php'))
$this->controller = $url[0];
unset($url[0]);

//_______________________________________________________________________
require_once 'controllers/'.$this->controller.'.php';
$this->contr_name = $this->controller;


$this->container = new Controllers_container;
$this->controller = new $this->controller($this->container);



//on declaring new object pass in tha paramaters??
//DIC and AUTOLOADER

//_______________________________________________________________________
if (isset($url[1]))
if(method_exists($this->controller, $url[1]))
$this->method = $url[1];
unset($url[1]);


//_______________________________________________________________________




//_______________________________________________________________________
$this->paramaters = $url ? array_values($url):;

call_user_func([$this->controller,$this->method],$this->paramaters);


public function parseURL()
if(isset($_GET['url']))
$url = explode('/', filter_var(rtrim($_GET['url'],'/'), FILTER_SANITIZE_URL));
return $url;









login controller:



<?php

class Login implements controllerInterface

protected $name = 'login';

protected $container;

protected $model_instance;

protected $data = ;

public function __construct(container $container)
$this->input = $container->loadInputArray();
$this->modelServices = $container->loadServices();
$this->model_instance = $container->loadModel($this->name , $this->input , $this->modelServices);


public function index()
$this->view->render($this->path, $this->data,$this->error);


public function user_login()
$this->model_instance->user_login($this->input);


public function user_logout()
$this->model_instance->user_logout();






login model:



<?php

class loginModel implements modelInterface

protected $name = 'login';

protected $model_lib;

protected $dbc;

protected $view;

protected $session;

protected $path;

protected $error;

protected $input;

protected $data_wrapper;

protected $data = ;

function __construct($array , modelServices $services )

$this->modelServices = $services;
$this->dbc= $this->modelServices->loadDatabase();
$this->model_lib= $this->modelServices->loadQuerys($this->dbc);
$this->data_wrapper= $this->modelServices->loadDataWrapper();
$this->view = $this->modelServices->loadView($this->name);
$this->session = $this->modelServices->loadSessions($this->name);
$this->input = $array;


public function user_login($input)
//print_r ($input->postArray);
if (!isset($input->postArray['submit_login']))
//$this->data = 'NO SUBMIT SENT';
$this->error = 'generic_error';
$this->view->render($this->path,$this->data_wrapper, $this->error);

else
if (empty($input->postArray['username'])


//$user_data = $this->model_lib->find_user_by_id($this->dbc);
//$this->view->render($user_data);




public function user_logout()

if (!isset($_POST['submit_logout']))
//$this->data = 'no submit posted';
$this->render->view($this->path,$this->data,$this->error);
else

$note = $this->session -> destroy_session();
if($note == true)
//$this->data = 'Loged out';
//header ('Location: index');
//$this->path = 'index';
$this->view->render($this->path,$this->data,$this->error);
else
//$this->data= 'could not destroy session';
$this->view->render($this->path,$this->data,$this->error);








Now a note: I used to create all dependencies before hand and then just pass them along.. however that seemed ineficient. so i split the dependency "generating" into two "services" classes - >controllers_container and modelServices (i am aware of the naming, and i will change that, sorry for presenting as is) and pass those, one to controllers and the other to models, and use them to call the rest. (This is the part I believe to be wrong).



here they are:



<?php


class Controllers_container implements container
protected $model_instance;

protected $dataWrapper_instance;

protected $inputArray_instance;

protected $modelServices_instance;

public function __construct()

public function __destruct()
$this->model_instance = NULL;


public function loadModel($name , inputCollector $input , modelServices $services)

require_once 'models/'.$name.'Model.php';
$this->model_instance = $name.'Model';
//--------------------------------
$this->model_instance = new $this->model_instance($input , $services);
return $this->model_instance;


public function loadServices()

$this->modelServices_instance = new modelServices;
return $this->modelServices_instance;



public function loadInputArray()
$this->inputArray_instance = new inputCollector;
return $this->inputArray_instance;







<?php


class Controllers_container implements container
protected $model_instance;

protected $dataWrapper_instance;

protected $inputArray_instance;

protected $modelServices_instance;

public function __construct()

public function __destruct()
$this->model_instance = NULL;


public function loadModel($name , inputCollector $input , modelServices $services)

require_once 'models/'.$name.'Model.php';
$this->model_instance = $name.'Model';
//--------------------------------
$this->model_instance = new $this->model_instance($input , $services);
return $this->model_instance;


public function loadServices()

$this->modelServices_instance = new modelServices;
return $this->modelServices_instance;



public function loadInputArray()
$this->inputArray_instance = new inputCollector;
return $this->inputArray_instance;






and the view:



<?php


class Controllers_container implements container
protected $model_instance;

protected $dataWrapper_instance;

protected $inputArray_instance;

protected $modelServices_instance;

public function __construct()

public function __destruct()
$this->model_instance = NULL;


public function loadModel($name , inputCollector $input , modelServices $services)

require_once 'models/'.$name.'Model.php';
$this->model_instance = $name.'Model';
//--------------------------------
$this->model_instance = new $this->model_instance($input , $services);
return $this->model_instance;


public function loadServices()

$this->modelServices_instance = new modelServices;
return $this->modelServices_instance;



public function loadInputArray()
$this->inputArray_instance = new inputCollector;
return $this->inputArray_instance;






PS. I know the functionality of classes can be improved (and it will be). My main problem is the DI and whether I am adhering to the MVC and SOLID principles.







share|improve this question













I started working in PHP and I wrote several things before I noticed that I'm not sure if I'm doing DI right. So, I need someone to review an example of my code and tell me what I did wrong, and I'm sure I did something wrong.



First a note, I am well aware of the DIC, however I decided not to go that way for this small project. The point of it is to get a firm footing in PHP, MVC and OOP before going onward to frameworks and their DIC ways.



The following code is just a login form and all the backend that goes with it.



The login form:



<form action="<?php echo URL; ?>login/user_login" method="POST">
<div class="form-inline ">
<label for="exampleInputPassword1" class="col-form-label col-form-label-sm"></label>
<input type="text" class="form-control form-control-sm" name="username" id="exampleInputPassword1" placeholder="Username">


<label for="exampleInputPassword2"></label>
<input type="password" class="form-control form-control-sm" name="password" id="exampleInputPassword2" placeholder="Password">


<button type="submit" name="submit_login" class="btn btn-primary btn-sm">Login</button>

</div>
</form>


bootstrap



<?php

class Bootstrap

protected $controller = 'index';

protected $method = 'index';

protected $paramaters = ;

protected $container;


//_________________
public function __construct()

session_start();

$url = $this->parseURL();

//_______________________________________________________________________

//_______________________________________________________________________
if(file_exists('controllers/'.$url[0].'.php'))
$this->controller = $url[0];
unset($url[0]);

//_______________________________________________________________________
require_once 'controllers/'.$this->controller.'.php';
$this->contr_name = $this->controller;


$this->container = new Controllers_container;
$this->controller = new $this->controller($this->container);



//on declaring new object pass in tha paramaters??
//DIC and AUTOLOADER

//_______________________________________________________________________
if (isset($url[1]))
if(method_exists($this->controller, $url[1]))
$this->method = $url[1];
unset($url[1]);


//_______________________________________________________________________




//_______________________________________________________________________
$this->paramaters = $url ? array_values($url):;

call_user_func([$this->controller,$this->method],$this->paramaters);


public function parseURL()
if(isset($_GET['url']))
$url = explode('/', filter_var(rtrim($_GET['url'],'/'), FILTER_SANITIZE_URL));
return $url;









login controller:



<?php

class Login implements controllerInterface

protected $name = 'login';

protected $container;

protected $model_instance;

protected $data = ;

public function __construct(container $container)
$this->input = $container->loadInputArray();
$this->modelServices = $container->loadServices();
$this->model_instance = $container->loadModel($this->name , $this->input , $this->modelServices);


public function index()
$this->view->render($this->path, $this->data,$this->error);


public function user_login()
$this->model_instance->user_login($this->input);


public function user_logout()
$this->model_instance->user_logout();






login model:



<?php

class loginModel implements modelInterface

protected $name = 'login';

protected $model_lib;

protected $dbc;

protected $view;

protected $session;

protected $path;

protected $error;

protected $input;

protected $data_wrapper;

protected $data = ;

function __construct($array , modelServices $services )

$this->modelServices = $services;
$this->dbc= $this->modelServices->loadDatabase();
$this->model_lib= $this->modelServices->loadQuerys($this->dbc);
$this->data_wrapper= $this->modelServices->loadDataWrapper();
$this->view = $this->modelServices->loadView($this->name);
$this->session = $this->modelServices->loadSessions($this->name);
$this->input = $array;


public function user_login($input)
//print_r ($input->postArray);
if (!isset($input->postArray['submit_login']))
//$this->data = 'NO SUBMIT SENT';
$this->error = 'generic_error';
$this->view->render($this->path,$this->data_wrapper, $this->error);

else
if (empty($input->postArray['username'])


//$user_data = $this->model_lib->find_user_by_id($this->dbc);
//$this->view->render($user_data);




public function user_logout()

if (!isset($_POST['submit_logout']))
//$this->data = 'no submit posted';
$this->render->view($this->path,$this->data,$this->error);
else

$note = $this->session -> destroy_session();
if($note == true)
//$this->data = 'Loged out';
//header ('Location: index');
//$this->path = 'index';
$this->view->render($this->path,$this->data,$this->error);
else
//$this->data= 'could not destroy session';
$this->view->render($this->path,$this->data,$this->error);








Now a note: I used to create all dependencies before hand and then just pass them along.. however that seemed ineficient. so i split the dependency "generating" into two "services" classes - >controllers_container and modelServices (i am aware of the naming, and i will change that, sorry for presenting as is) and pass those, one to controllers and the other to models, and use them to call the rest. (This is the part I believe to be wrong).



here they are:



<?php


class Controllers_container implements container
protected $model_instance;

protected $dataWrapper_instance;

protected $inputArray_instance;

protected $modelServices_instance;

public function __construct()

public function __destruct()
$this->model_instance = NULL;


public function loadModel($name , inputCollector $input , modelServices $services)

require_once 'models/'.$name.'Model.php';
$this->model_instance = $name.'Model';
//--------------------------------
$this->model_instance = new $this->model_instance($input , $services);
return $this->model_instance;


public function loadServices()

$this->modelServices_instance = new modelServices;
return $this->modelServices_instance;



public function loadInputArray()
$this->inputArray_instance = new inputCollector;
return $this->inputArray_instance;







<?php


class Controllers_container implements container
protected $model_instance;

protected $dataWrapper_instance;

protected $inputArray_instance;

protected $modelServices_instance;

public function __construct()

public function __destruct()
$this->model_instance = NULL;


public function loadModel($name , inputCollector $input , modelServices $services)

require_once 'models/'.$name.'Model.php';
$this->model_instance = $name.'Model';
//--------------------------------
$this->model_instance = new $this->model_instance($input , $services);
return $this->model_instance;


public function loadServices()

$this->modelServices_instance = new modelServices;
return $this->modelServices_instance;



public function loadInputArray()
$this->inputArray_instance = new inputCollector;
return $this->inputArray_instance;






and the view:



<?php


class Controllers_container implements container
protected $model_instance;

protected $dataWrapper_instance;

protected $inputArray_instance;

protected $modelServices_instance;

public function __construct()

public function __destruct()
$this->model_instance = NULL;


public function loadModel($name , inputCollector $input , modelServices $services)

require_once 'models/'.$name.'Model.php';
$this->model_instance = $name.'Model';
//--------------------------------
$this->model_instance = new $this->model_instance($input , $services);
return $this->model_instance;


public function loadServices()

$this->modelServices_instance = new modelServices;
return $this->modelServices_instance;



public function loadInputArray()
$this->inputArray_instance = new inputCollector;
return $this->inputArray_instance;






PS. I know the functionality of classes can be improved (and it will be). My main problem is the DI and whether I am adhering to the MVC and SOLID principles.









share|improve this question












share|improve this question




share|improve this question








edited Jul 18 at 16:32









200_success

123k14143399




123k14143399









asked Jul 18 at 16:26









BlackBit

6




6











  • Welcome to Code Review! Does the code currently work as intended?
    – Mast
    Jul 18 at 16:34










  • Hi, and ty. Yes, it works perfectly. However, i would still like to know if i adhere to the principles.
    – BlackBit
    Jul 18 at 16:37
















  • Welcome to Code Review! Does the code currently work as intended?
    – Mast
    Jul 18 at 16:34










  • Hi, and ty. Yes, it works perfectly. However, i would still like to know if i adhere to the principles.
    – BlackBit
    Jul 18 at 16:37















Welcome to Code Review! Does the code currently work as intended?
– Mast
Jul 18 at 16:34




Welcome to Code Review! Does the code currently work as intended?
– Mast
Jul 18 at 16:34












Hi, and ty. Yes, it works perfectly. However, i would still like to know if i adhere to the principles.
– BlackBit
Jul 18 at 16:37




Hi, and ty. Yes, it works perfectly. However, i would still like to know if i adhere to the principles.
– BlackBit
Jul 18 at 16:37















active

oldest

votes











Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");

StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f199763%2fa-basic-mvc-with-routing-and-login-system-in-php%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes










 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f199763%2fa-basic-mvc-with-routing-and-login-system-in-php%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Python Lists

Aion

JavaScript Array Iteration Methods