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

  • Home
  • SEARCH
  • 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 557343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:00:59+00:00 2026-05-13T12:00:59+00:00

EDIT: What is the best way to structure complex applications with CodeIgniter? To make

  • 0

EDIT:

What is the best way to structure complex applications with CodeIgniter? To make this question more specific, maybe to just focus on structuring controllers: If you have a Users controller, than should all functions be in this one file? In other words, you might have controller actions that tie to specific views, but a bunch of helper functions as well.

ORIGINAL QUESTION: Given a complex application, with Users, Transactions, Products, does it make sense to have a Controller for each of them? And since each of these corresponds to a database table, to have a corresponding model for each of them? I think it does, but an application I am currently working on consists of one 3000 line controller and one 3000 line model. Just want to verify the standard practice regarding CI and the application structure.

  • 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-13T12:00:59+00:00Added an answer on May 13, 2026 at 12:00 pm

    I’d like to share my application structure here.

    I start with model. I write 1 model for one table in the mysql database. I already have MY_Model class that I put in system/application/libraries/ folder. This class have get_detail, get_list, get_total, get_all, insert, update, and delete method. I store the table name in a var, so basically I just need this code in model to make it worked:

    class Some_table_model extends MY_Model {
      function Some_table_model()
      {
        $this->tablename = 'some_table';
        $this->primary_key = 'id';
      }
    
    }
    

    Update: after some more project, I have added new var to hold the column name used for primary key in the table. This way, I will have more flexibility by not hard coded the column name for primary key in MY_Model.

    For the controller, I create it according to it’s usage by user. Example for a product, I will have this controller:

    function Product extends Controller {
      function index()
      {
        //display product list, paginated
      }
      function admin()
      {
        //protected by session
        //display product list for admin, paginated
        //handle POST request to delete a product or products
      }
      function form()
      {
        //protected by session
        //handle add/edit product for admin
      }
    }
    

    View is related to controller. For above controller, I will have at least 3 view file:

    product_list.php
    product_admin.php
    product_form.php
    

    View can be placed in subdir, for example, I can arrange it like this:

    system/application/views/front/product.php
    system/application/views/admin/product_list.php
    system/application/views/admin/product_form.php
    

    If product have category, I will need another table and model for it, but for controller, I can put the page inside Product controllers, by adding category into the function name:

    function category_admin()
    {
      //get parameter
      //...
      //process data
      //...
      //redirect or load view
      //...
    }
    
    function category_form()
    {
      //get parameter
      //...
      //process data
      //...
      //redirect or load view
      //...
    }
    

    That’s what I do and it’s work for me. Hope this help you find a better way to refactor your CodeIgniter’s code.

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

Sidebar

Ask A Question

Stats

  • Questions 375k
  • Answers 375k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer @implementation NSString (MySort) - (int) myValue { NSArray *nameSegments =… May 14, 2026 at 8:13 pm
  • Editorial Team
    Editorial Team added an answer As other folks noted, it's Process.Start. Example: using System.Diagnostics; //… May 14, 2026 at 8:13 pm
  • Editorial Team
    Editorial Team added an answer Try using a WebViewClient, overriding its onReceivedHttpAuthRequest() method. May 14, 2026 at 8:13 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.