loadView()

loadView($view, $data, $toVar = false)

Loads a view, process data and print/store it.
@param String $view
@param Array $data
@param Boolean $toVar
@return String

Params


$view
View is the complete folder/subfolder/file reference with some particularities: you don’t have to say the extension because it is defined by your configuration, if you want to change you view system tomorrow you can just by changing configs, not the application.

Other particularity is that you only have to call from root view path ( SYS_VIEW_PATH ) for example if your users/list.php are at /var/www/html/mySite/system/views/users/list.php you just use “user/list”.

$data
All the data that will be parsed by views parser, it should always be an Array and if you want to customize your own View System, you can handle it into your View System Class.

$toVar
That will say to loadView() that your view should not be printed as soon you call it but instead you will store it into a variable:
example: $myView = $loadView(‘wellcome’, $arrData, true);

Explanation


You should display somehow your html, xml, html5, etc… so that’s the method you will call to it… you can concatenate or include lots of this into your controller.

Default Usage
Your View (hello.php)

This is an example: <?=$content?>

Your Controller

class admin extends Controller {
    public function index() {
        $arrData['content'] = "Hello World";
        
        $this->loadView('hello',$arrData);
    }
}

That will produce a: “This is an example: Hello World

Other usages

class admin extends Controller {
    public function index() {
        $arrData['content'] = "Hello World";
        
        $myView = $this->loadView('hello',$arrData, true);
        print "Now we execute other actions before print - ";
        print $myView;
    }
}

That will produce a: “Now we execute other actions before print – This is an example: Hello World

BE CREATIVE