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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:16:53+00:00 2026-05-24T07:16:53+00:00

<?php class Home extends CI_Controller { public function __construct() { // load libraries //

  • 0
<?php
class Home extends CI_Controller
{
    public function __construct()
    {
        // load libraries //
        $this->load->library('session');
        $this->load->library('database');
        $this->load->library('captcha');

        // alternative
        $this->load->library(array('session', 'database', 'captcha'));

        // load models //
        $this->load->model('menu_model', 'mmodel');
        $this->load->model('user_model', 'umodel');
        $this->load->model('admin_model', 'amodel');

        // alternative
        $this->load->model(array(?));
    }
}
?>

How can i load all models in array? is it possible?

  • 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-24T07:16:54+00:00Added an answer on May 24, 2026 at 7:16 am

    For models, you can do this:

    $models = array(
        'menu_model' => 'mmodel',
        'user_model' => 'umodel',
        'admin_model' => 'amodel',
    );
    
    foreach ($models as $file => $object_name)
    {
        $this->load->model($file, $object_name);
    }
    

    But as mentioned, you can create file application/core/MY_Loader.php and write your own method for loading models. I think this might work (not tested):

    class MY_Loader extends CI_Loader {
    
        function model($model, $name = '', $db_conn = FALSE)
        {
            if (is_array($model))
            {
                foreach ($model as $file => $object_name)
                {
                    // Linear array was passed, be backwards compatible.
                    // CI already allows loading models as arrays, but does
                    // not accept the model name param, just the file name
                    if ( ! is_string($file)) 
                    {
                        $file = $object_name;
                        $object_name = NULL;
                    }
                    parent::model($file, $object_name);
                }
                return;
            }
    
            // Call the default method otherwise
            parent::model($model, $name, $db_conn);
        }
    }
    

    Usage with our variable from above:

    $this->load->model($models);
    

    You could also allow a separate DB connection to be passed in an array, but then you’d need to have a multidimensional array, and not the simple one we used. It’s not too often you’ll need to do that anyways.

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

Sidebar

Related Questions

This is my AdminBase.php <?php class AdminBase extends Controller{ public function __construct(){ parent::Controller(); $admin
Model : <?php class Blogm extends CI_Model{ function __construct() { // Call the Model
I have the following code in a controller: <?php class Student extends CI_Controller {
Please consider the following code: <?php class MyException extends Exception {} function global_exception_handler($exception) {
Hey, I'm trying to do something like this: <?php class MySmarty extends Smarty {
Here is my controller: <?php namespace Home\JoinBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Home\JoinBundle\Entity\User; class DefaultController extends
Is there a PHP class/library that would allow me to query an XHTML document
I currently have my PHP class variables set up like this: class someThing {
I'm using this php class ( http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php ) for creating the different sized images
I get the above error when calling this code: <? class Test1 extends Core

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.