Miscellaneous Code

  Home arrow Miscellaneous Code arrow Model Data and Validation Rules for a ...
MISCELLANEOUS CODE

Model Data and Validation Rules for a Generic CodeIgniter PHP Framework Model
By: Alejandros Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2009-08-19

    Table of Contents:
  • Model Data and Validation Rules for a Generic CodeIgniter PHP Framework Model
  • Review: the initial definition of the generic model class
  • Setting validation rules and input data for the model
  • The enhanced version of the generic model class

  •  
     

    SEARCH CODEWALKERS

    Model Data and Validation Rules for a Generic CodeIgniter PHP Framework Model


    (Page 1 of 4 )

    Welcome to the second part of an eight-part series on building a generic model for the CodeIgniter PHP framework. In this part, I will expand the functionality of the “AbstractModel” class we created in the first part by adding a couple of handy methods to it. Keep reading for the full details.

    If you’ve ever built PHP applications with the CodeIgniter framework, then you know how useful it can be for speeding up the whole development process, due to its powerful capabilities and flat learning curve. What’s more, its solid implementation of the Model-View-Controller pattern permits you to quickly separate data and application logic from visual presentation, thus facilitating creating programs that are maintainable and modular as well.

    However, all of these advantages can be empowered even further with the existence of a single highly-functional generic model class that allows you to perform CRUD operations against multiple database tables through a group of simple sub classes. So, if you’re interested in learning how to build a model like this, then you might want to look at this series of articles. In it, you’ll be provided with a comprehensive guide that will walk you through this process in a step-by-step fashion. 

    In the first part of this series, I proceed to create the basic structure of a generic model class called “AbstractModel.” It defined some straightforward methods (apart from the constructor) for setting and retrieving the value of the “id” field corresponding to the database associated with the model. 

    Nonetheless, the model class in its current state is pretty useless; we need to define a few more methods that make it a bit more functional. Therefore, in the next few lines I’m going to code a couple of brand new methods. The first one will be responsible for setting the data the model will take for performing insert/updates operations, and the last one will be tasked with configuring the validation rules that will be applied to this data. 

    Now, it’s time to leave the theory behind and start writing these methods of the generic model class. Let’s jump in!

    More Miscellaneous Code Articles
    More By Alejandros Gervasio

    blog comments powered by Disqus

    MISCELLANEOUS CODE ARTICLES

    - Creating a Web Page Controller with the HMVC...
    - Coding Controllers and Views for the HMVC De...
    - A Sample Web Application with the HMVC Desig...
    - Adding a Class to Parse Views to an HMVC Des...
    - Building a Model Class for the HMVC Design P...
    - Filtering Input Data and Generating HTML For...
    - The HMVC Design Pattern: Working with MySQL ...
    - Dispatching Requests to MVC Triads with the ...
    - Implementing the Hierarchical Model-View-Con...
    - A Web App Based on a Model for the CodeIgnit...
    - Completing a Model for the CodeIgniter PHP F...
    - Validating Input Data with the CodeIgniter P...
    - Deleting Database Records with the CodeIgnit...
    - Inserting Database Records with a CodeIgnite...
    - Fetching Database Rows with a Model for the ...

    Developer Shed Affiliates

     



    © 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap