Completing a Model for the CodeIgniter PHP Framework - Completing the AbstractModel class
(Page 3 of 4 )
As I stated in the section that you just read, the model needs to be able to resent its properties, and build the error strings that will be shown when validating incoming data and performing CRUD operations as well. With that idea in mind, below I included the definition of a few extra methods that accomplish all of these things in a pretty straightforward fashion. Look at them, please:
/**
* Gets model errors
*
* @author Alejandro Gervasio
* @param string
* @return string
* @access public
*/
public function getErrors($errPrefix = '<p>')
{
// if no errors where found return an empty string
As illustrated above, I coded a couple of extra methods, called “getErrors()” and “clear()” respectively. The first one is charged with building the error messages that will be displayed to users when certain types of failures occur, and the last one is responsible for resetting the model’s state. Of course, both of these methods can be enhanced in all sorts of clever ways, but for now this will be left as homework for you.
Well, after incorporating the previous methods into the generic model class, it's nearing completion and to be fair, it’s almost ready to be used in a real-world environment. However, the complete source code of the class will be listed in the last section of this tutorial, thus finishing its development.
So, if you wish to see how the completed class will look, go to the following segment and keep reading.