4. Models

Created Tuesday 21 January 2014

http://www.nathandavison.com/article/8/custom-php-mvc-tutorial-part-4-models

  1. models/home.php
class HomeModel extends BaseModel
{
public function Index()
{
return array("Value 1", "Value 2", "Value 3");
}
}

  1. controllers/home.php
class Home extends BaseController
{
protected function Index()
{
$viewmodel = new HomeModel();
$this->ReturnView($viewmodel->Index(), true);
}
}

  1. classes/basemodel.php
abstract class BaseModel {
protected $database;
public function __construct() {
$this->database = new PDO("mysql:host=localhost;dbname=test", "username", "password");
}
}



Backlinks: