Welcome Guest, Not a member yet? Register   Sign In
Indirect modification of overloaded property Template::$CI has no effect
#1

[eluser]johnmerlino[/eluser]
Hey all,

I'm getting this error:

A PHP Error was encountered

Severity: Notice

Message: Indirect modification of overloaded property Template::$CI has no effect

Filename: libraries/Template.php

Line Number: 50

Fatal error: Cannot assign by reference to overloaded object

Basically in the Template library, which is autoloaded, I have a method called render_content:

Code:
function render_content($template = '', $view = '' , $data = array(), $return = FALSE){              
        $this->CI =& get_instance();
        
        $this->title = "Default Title";
        $this->subtitle = "Default Subtitle";
        
        $this->_data = array_merge($this->_data, $data);
        
        $this->set('yield', $this->CI->load->view($view, $_data, TRUE));            
        return $this->CI->load->view($template, $this->template_data, $return);
    }

Basically, it sets a default title and subtitle and stores it into $_data array:

Code:
public function __set($name, $value){
        $this->_data[$name] = $value;
    }

Then in controller I set some variables that override the defaults in Template:

Code:
public function signup(){
            
            $this->template->render_content('template', '/users/signup', array('title' => 'Signup Form', 'subtitle' => 'Free Case Evaluation'));

I think it has something to do with __set method, which overloads. But I don't know what else to do.

Thanks for response.
#2

[eluser]WanWizard[/eluser]
You get this error from
Code:
$this->CI =& get_instance();

Apprearenly, $this->CI is an assigned reference, and since PHP 5.2, you can't assign something else by reference to it without first erasing it.

Instead, use
Code:
//test before assignment
$this->CI || $this->CI =& get_instance();

// or assign without reference (which is default)
$this->CI = get_instance();

// or unset the previous reference first
$this->CI = '';
$this->CI = get_instance();

// or use chaining
get_instance()->load->view(...)
#3

[eluser]johnmerlino[/eluser]
Thanks for response. Your solution works.




Theme © iAndrew 2016 - Forum software by © MyBB