3. Controllers

Created Tuesday 21 January 2014
http://www.nathandavison.com/article/9/custom-php-mvc-tutorial-part-3-controllers

  1. basecontroller.php
abstract class BaseController {
    protected $urlvalues;
    protected $action;

    public function __construct($action, $urlvalues) {
        $this->action = $action;
        $this->urlvalues = $urlvalues;
    }

    public function ExecuteAction() {
        return $this->{$this->action}();
    }

    protected function ReturnView($viewmodel, $fullview) {
        $viewloc = 'views/' . get_class($this) . '/' . $this->action . '.php';
        if ($fullview) {
            require('views/maintemplate.php');
        } else {
            require($viewloc);
        }
    }
}

  1. controllers/home.php
class Home extends BaseController
{
protected function Index()
{
$viewmodel = "Just a basic string";
$this->ReturnView($viewmodel, true);
}
}



Backlinks: