Model variable in view?

Permalink 1 user found helpful
I wrote in my model to list database items like...
public function leavecategory() {
$cat=$db->GetArray("SELECT lc_category FROM `lms_leave_category`");
return $cat;
}

I want to use this $cat in my view to list in a select box...
How can I use this variable in my view page...
There is any suggestions?

cjramki
 
Remo replied on at Permalink Reply
Remo
use a controller to forward the result to the view

your_controller.php:
public function test() {
   $m = Loader::model('your-model...);
   $this->set('var', $m->leavecategory());
}


in your_view.php:

print_r($var);
cjramki replied on at Permalink Reply
cjramki
Ya its working... But I want to load this controller when the page is load...Where i place the code for page load?
kingdt replied on at Permalink Reply
You need to place the code in your controller file in the 'public function on_start' part:

public function on_start() {
   $this->test();
}
private function test() {
   $m = Loader::model('your-model...);
   $this->set('var', $m->leavecategory());
}
Remo replied on at Permalink Reply
Remo
You shouldn't use on_start if it's just about viewing the page. I'd recommend the view method which isn't called as much as on_start