This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
lnkohana/system/guide/kohana/mvc/models.md
2013-04-22 14:09:50 +10:00

789 B

Models

From Wikipedia:

The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller).

Creating a simple model:

class Model_Post extends Model
{
	public function do_stuff()
	{
		// This is where you do domain logic...
	}
}

If you want database access, have your model extend the Model_Database class:

class Model_Post extends Model_Database
{
	public function do_stuff()
	{
		// This is where you do domain logic...
	}

	public function get_stuff()
	{
		// Get stuff from the database:
		return $this->db->query(...);
	}
}

If you want CRUD/ORM capabilities, see the ORM Module