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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:57:32+00:00 2026-05-23T09:57:32+00:00

When you are using code igniter you load a library or model like so

  • 0

When you are using code igniter you load a library or model like so

$this->load->library('mylibrary');  
$this->load->model('mymodel');

So, in a real world example, lets say you have a controller called user.

So, to login a user you send them to http://example.com/user/login

Now the login function loads a form that submits to http://example.com/user/login_do
You do some simple checks, and then send it over to your model to do the database check for you.

So you call

$this->load->model('user');
if($this->user->validate($email, $pass)){...}

UH OH!

Fatal error: Cannot redeclare class
User in
/var/www/unity/src/application/models/User_Model.php
on line …

So what happened? Well, Code igniter does not segregate the classes, so your model now conflicts with your controller,

sure you can use

$this->load->model('user_model', '', 'user_m');
if($this->user_m->validate($email, $pass)){...}

So, Onto my question.

Why does code igniter not segregate the classes,
e.g. so you would call

$this->load->model('user');
if($this->model->user->validate($email, $pass)){...}

Sure it’s slightly longer, but hell it would make things heaps nicer to user.
is it possible to extend code igniter so it works in this way?

  • 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-23T09:57:32+00:00Added an answer on May 23, 2026 at 9:57 am

    It’s not exactly the solution you’re asking for (or a great idea), but there’s nothing stopping you from doing this:

    class Users extends CI_Controller {
    
        private $model;
        private $m;
    
        public function __construct()
        {
            parent::__construct();
            $this->load->model('user_model');
            $this->model->users = $this->user_model;
            $this->m = $this->user_model;
        }
    
        function index()
        {
            // Here's that syntax you wanted
            $this->model->users->get_many();
    
            // Even shorter
            $this->m->get_many();
        }
    
    }
    

    You can really just assign anything to any property of the controller you want, as long as it’s not the name of a loaded class or property (session, router, etc.). It can save you some typing if your model names are really long, but otherwise it’s pointless and may conflict with things in the future.

    Here’s what I do if I’m not using *_model for model names:

    • Controller name: Users (plural)
    • Model name: User (singular)

    No conflict, short syntax, sensible naming, it just doesn’t work for some names like “news”.

    As I mentioned, it would be nice to see controller names using something like Controller_User or User_Controller to clear up the namespace issues a bit for the classes that we actually do have to call frequently, like models and libraries, but keep our urls as normal. I’m sure it can be done, something for a rainy day…

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

Sidebar

Related Questions

It's ok to upload image in file using codeigniter upload library with this example.
I have been using code similar to this MessageDlg('', mtWarning, [mbOK], 0); throughout my
I am using code-igniter, and some of my views require jquery. Because they must
I am writing a webapp using CodeIgniter that requires authentication. I created a model
I'm using code that I found on the CodeProject.com for a low-level keyboard hook
I've recently started using code coverage tools (particularily Emma and EclEmma), and I really
I'm using code that takes a bitmap and converts it to 24 BPP so
Using the code below, I am returning an nvarchar field from MS SQL 2005
using the Code Snippet for sending email in VB.Net I have successfully sent an
I am doing a multiple upload using the Multiple_upload library in codeigniter, and form

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.