How to load model in controller in kohana3.3.1?

793 Views Asked by At

How to load model in kohana and how to call the methods of this model to retrieve some data from database and show the data in views. Just like in codeigniter, I want to load the model in controller,call its method say getAll(), and then pass this data to view.

Can anybody help me in this?

Thanks.

1

There are 1 best solutions below

0
On

Kohana uses "Autoloading". If it doesn't find a class, it will search for it. You can read about it here http://kohanaframework.org/3.3/guide/kohana/autoloading .

You just need to write in your controller

public action_index()
{
    $model = new Model_Foo;

    $items = $model->get_all();
    ...
}

This depends on you to have a get_all() function in your model. You can use ORM models or create your own. Read in the docs about it here http://kohanaframework.org/3.3/guide/kohana/mvc/models .