Welcome Guest, Not a member yet? Register   Sign In
Error in model when trying to change variables: modification of overloaded property
#1

[eluser]Mark75[/eluser]
Hello,

i'm currently converting my site to ci 2.0 - running into a php5 problem, i think.

in a model i try to change a variable like this:

Code:
$this->data['meta']->meta_title =  'postname - ' . $this->data['meta']->meta_title;

$this->data['meta'] is defined outside the model in a MY_Controller like this:
Code:
$this->data = array(
  'meta' => $this->meta_model->get_meta()
);

Anyway, when i try to assign the postname to $this->data['meta']->meta_title i get an error:
Code:
Indirect modification of overloaded property Blog_model::$data has no effect

Can anyone help?

Regards,
Mark
#2

[eluser]Unknown[/eluser]
Replace the line:
function __get($key){
with
function &__get($key){
in "system/core/Model.php"
#3

[eluser]tical[/eluser]
I was having a very similar problem to Mark75, and Alfonso Rubalcava's solution worked.

However, I don't like editing CI system files if I can help it.
Is this a bug in CI2.0 or should I change the way I share variables between models, controllers, libraries etc?

In my example, I had a variable like
Code:
$this->_data_example
defined in my library, then I had a model trying to assign a value to this as
Code:
$this->example_library->_data_example = $data

This was then returning the same error as Mark75's.
This error only occurred when I updated the site from an early pre-release of CI2.0 to the official 2.0 release version.
#4

[eluser]InsiteFX[/eluser]
You can always create and extend the CI_Model - MY_Model

If you extend the model make sure you place it in application/core

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB