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

The Archive Base Latest Questions

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

I have been wondering is it possible to assign another object to $this? In

  • 0

I have been wondering is it possible to assign another object to $this?

In CodeIgniter I am calling another controller from main controller.

application/controllers/module.php

Class Module extends CI_Controller {
    public function __construct() {
        parent::__construct();
    }

    public function _remap($class, $args = array()) {
        // doing some checks that is there a valid file, class and method
        // assigning the $method.
        // including MY_Module class. I'am extending every module from this class.
        // then:
        $EG = new $class();
        call_user_func_array(array(&$EG, $method), array_slice($this->uri->rsegments, 3));
    }
}

In called class:

Class Users extends MY_Module
{
    public function __construct() {
        parent::__construct();
    }

    public function index() {
        // Want to use this class and method like it is a codeigniter controller.
    }
}

MY_Module:

Class My_Module {
    public function __construct() {
        $this =& CI_Controller::get_instance(); // Here is problem.
    }
}

I want to use instantiated class’ declaretion to My_Module class. So that it wont initialize same libraries and won’t spend more resource.

How can I accomplish that?

Thanks for advices.

EDIT: I tried to extend MY_Module from CI_Controller. But since its already instantiated once, it is causing problems.

  • 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-23T02:18:58+00:00Added an answer on May 23, 2026 at 2:18 am

    You can’t “inject” a reference to your current $this object. And even if that was possibile i would strongly advise against.

    Just assign the reference to another var and use from it.

    public function __construct() {
        $yourSingleton = CI_Controller::get_instance(); 
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

so, just wondering if this is even possible i have been using the editor
I have been wondering and couldn't find a clear answer on this subject. Imagine
I ran into this RegExp /[[0]]/ in JavaScript, and have been wondering what it
Alright, so I have been wondering how to do this for a while. Basically,
I am wondering if it's possible to restore dropdown values once they have been
I have been using Codeigniter with Doctrine 1.2.3 and I am wondering is it
I have been researching Mobile Agents, and was wondering if it is possible to
I wondering if something similar to this is possible. Basically, I have a templated
I have been using this logic to render templates in my GAE application: path
I've been wondering if it's possible to have Fluent-NHibernate communicate with stored procedures that

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.