negative(-11) Documentation

Documentation Home

Components

Components are used to provide additional functionality to the framework when the use of another type would not be appropriate. Controllers are for business logic, Models are for data handling, and Templates are for markup and display logic.

Real-world Example

A MySQL Component creates an abstraction layer for connecting to, querying, managing results from, and preparing data for a MySQL database. It's scope is beyond that of a Controller, and a template certainly won't do! Why not use a model? Didn't we say that models are for handling data? Yes, models are for handling data, but not for fetching data from a database. All the model really cares is that it receives the data it requires, whether it be formatted in XML, array, CSV, or other. It is completely uninterested in how the data is collected. This is where the Component comes into play.

Why?

A component provides special functionality beyond the scope of a model, whose primary purpose is to prepare data for the Controller. Could the functionality be placed in a model? Sure, but making this distinction helps keep the framework organized. A User_Model class is for manipulating a user's data: create, read, update, delete, and so on. A User_Component could be used to generate suggestions for alternate usernames, or maybe to ensure all data has been validated for new user signups before supplying it to the model for insertion. They are versatile 'components' that can be used for a variety of tasks.


© Copyright 2010 negative11.com