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 6688959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:27:49+00:00 2026-05-26T05:27:49+00:00

i´m trying to structure my functions in codeigniter to stay on top of things.

  • 0

i´m trying to structure my functions in codeigniter to stay on top of things. Basicly i can make something like that:

$this->my_model->get_everything();
$this->my_model_db->write_all();

But of course i end up making and loading many files. I´d rather structure it like my JS-code and extend my models:

$this->my_model->db->write_all();

It´s the most logical and readable solution to me. I tried it but i´m not that good with PHP objects and classes (yet). Is there an simple way to achive this? Or is there a more practical solution? Thanks!

  • 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-26T05:27:49+00:00Added an answer on May 26, 2026 at 5:27 am

    I think you are doing it backwards.

    You can create multiple models that extend the built in CI_Model class with the general functions you want. Then you can inherit from those new classes for specific implementations.

    For example, let’s say you’re working with a db table name Accounts

    First, create a class that extends CI_Model that contains general functions for working with a set of data (CI_DB_Result, an array of models, an array of arrays, etc). Something like:

    abstract class table_model extends CI_Model
    {
      function __construct()
      {
        parent::__construct();
      }
    
      public function write_all()
      {
        // do some stuff to save a set of data
        // maybe add some logging in here too, if it's on development
        // and how about some benchmarking for performance testing too
        // you get the idea
      }
    }
    

    Next, create a class that extends table_model but with functions specific to the Accounts table.

    public class accounts_model extends table_model
    {
      function __construct()
      {
        parent::__construct();
      }
    
      public function get_everything()
      {
        // whatever it takes to get everything...
      }
    }
    

    Finally, you can do stuff like…

    $this->account_model->get_everything();
    $this->account_model->write_all();
    

    And if you have another model (my_model) you can also do:

    $this->my_model->get_just_a_few_things();
    $this->my_model->write_all();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a structure that can be dynamically added to with
I'm trying to use the Rect structure from System.Windows in MonoDevelop, but I can't
I am trying to create a wizard like structure using dialog boxes...So I replaced
I am trying to make global structure, which will be seen from any part
I am trying to decide on a data structure for an array that has
I have two C functions, which basically operate on a stack data structure. This
I have an array of a large structure that I am trying to output
I'm trying to figure out how to use this directory_map function in CodeIgniter. See
im trying to understand the framework structure in CodeIgniter and i have just started
I'm trying to work with a data structure that deals with tuples, however I

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.