Model variable in view?
Permalink 1 user found helpful
I wrote in my model to list database items like...
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?
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?
Ya its working... But I want to load this controller when the page is load...Where i place the code for page load?
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()); }
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
your_controller.php:
in your_view.php: