I am newbie to class and objects.Here I am making an application for invoice.So for the controllers as in the frameworks I have taken them as handlers.So for the UserHandler
I have made this query:
<?php
class UserHandler {
public $db;
public function __construct($db) {
$this->db = $db;
}
public function index() {
print_r($this->db->query("SELECT * FROM nt_user"));
}
}
It is showing result in array as I want like that.
Array ( [0] => 1 [id] => 1 [1] => xyz [name] => xyz [2] => 5d6305f2 [password] => 5d6305f2 [3] => 2011-05-24 14:59:17 [created_at] => 2011-05-24 14:59:17 [4] => 2011-05-24 14:59:17 [updated_at] => 2011-05-24 14:59:17 )
Now I want to show that result in a view template.As view template is another file how to render all the values of handlers to the view.
I want the view page show like this:
name:
Password:
just like the login box.So please tell me how to do that?
You can create a static class using magic methods __get and __set to the the values like:
To set a value, you use:
Data::__set('view_data', $my_var);On the view you just do:
Data::__get('view_data');I think it will work =)