Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6192457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:56:46+00:00 2026-05-24T02:56:46+00:00

I’m currently making an app in CodeIgniter and I was wondering on how I

  • 0

I’m currently making an app in CodeIgniter and I was wondering on how I should deal with models. The way I have it set up at the moment:

Views: display
Controllers: display related things, form validation, redirects, talk to libraries, etc
Libraries: do the heavy lifting, talk to the models, generate error messages, logs, etc
Models: talk to the DB

(I’m currently using Active Record for most things)

Let me go straight to an example:

I have an Auth library and inside I have queries that area somewhat similar, varying only by the value in the WHERE clause.

Ex:

get_by_id($id);
get_by_password_hash($email);
get_by_email($email);

Should I have a bunch of these duplicate model functions or should I just have one simple function where I pass WHERE clauses and whatnot via the library?

Ex:

$where = array('id' => $id);
get($where);

Please let me know if you’d like me to clarify anything.
Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:56:48+00:00Added an answer on May 24, 2026 at 2:56 am

    If you have a lot of get_by_* methods for a given model, then it does make sense to use the magic method as TaylorOtwell suggested. Actually, the __call method, as well as __get and __set are used frequently in other frameworks to make it easy to do exactly what you’re talking about. Just remember CI will not play nice with the __call Magic method on the controller while mapping (but that won’t effect the model).

    Basic way I look at CMV in CI:

    • Libraries — this is where the bulk of the “rendering logic” happens but generally should be control/model/view agnostic. Almost entirely stateless (my preference).
    • Helpers — utility functions, mostly view-related (everything else is really better off as a library (more orthogonal, yada, yada, yada))
    • Controller — Loads libraries/models and calls methods
    • Model — DB wrapping layer. Almost entirely stateful (my preference).
    • Views — Display data

    Frequently, the controller will do things like:

    class Users
    {
        function display( $id )
        {
            $this->load->library( 'myformatlib' );
            $this->load->model( 'mymodel' );
            $data = $this->mymodel->get_user( $id );
            $formatted = $this->myformatlib->addColors( $data );
            $this->mymodel->incrementViews( $id );
            $this->load->view( 'full_user', $formatted );
        }
    }
    

    As to passing where clauses — DB queries should almost be exclusively relegated to the model unless there is no other option or it would be excessively cumbersome to do so (but I would wonder if you couldn’t refactor that).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.