Welcome Guest, Not a member yet? Register   Sign In
Minimalist View Library
#1

[eluser]Unknown[/eluser]
Since the standard way of passing data to a view is kinda awkward (array syntax is ugly and there's no real reason for having a local variable for something that's not used locally) i put together a little library that makes it behave like I want it to. Smile

So, here's the library:

libraries/view.php
Code:
<?php
class View {
    public function display($template) {
        get_instance()->load->view($template, $this);
    }
}

And this is a sample controller:

controllers/welcome.php
Code:
<?php
class Welcome extends Controller {
    function Welcome() {
        parent::Controller();    
    }
    
    function index() {
        $this->view->message = 'Hello there!';
        $this->view->display('welcome_message');
    }
}

There's no difference for views. It doesn't do much, but I think it makes the code a little tidier and easy to read.




Theme © iAndrew 2016 - Forum software by © MyBB