Welcome Guest, Not a member yet? Register   Sign In
HMVC / MX_Controller / Undefined property
#1

[eluser]Mark75[/eluser]
Hi,

i just installed HMVC in a blank Codeigniter Installation. Everything worked fine until i wanted to include my auth-Controllers. Perhaps someone has an idea what is going wrong?

I created the file MX_Controller in /libraries with the following source:
Code:
<?php if( ! defined('BASEPATH') ) exit('No direct script access allowed');

class Public_Controller extends Controller {

    function Public_Controller()
    {
        parent::Controller();
        $this->data->user = $this->auth->get_user($this->session->userdata('user_id'));
    }

}

This is my welcome-Controller (already working in module-directory)
Code:
<?php

class Welcome extends Public_Controller {

    function Welcome()
    {
        parent::Public_Controller();    
    }
    
    function index()
    {
        $this->load->view('welcome_message');
    }
}

When i reload my page i get the following errors:

Code:
Undefined property: CI::$data
Filename: libraries/Controller.php
Line Number: 377

Indirect modification of overloaded property Welcome::$data has no effect
Filename: libraries/MX_Controller.php
Line Number: 8



I think that is has something to do with the __get function in Controller.php and my PHP-Version (currently 5.2). I just cant figure out what?
$this->data->user in Public_Controller is FALSE when no user is logged in.

Any help would be greatly appreciated

Mark
#2

[eluser]wiredesignz[/eluser]
You must add the $data class variable to your Public_controller class.

PHP5 is looking for a $this->data object so that it can add the $user variable.

If the $data object doesn't exist PHP5 then uses the overload method to try to __get $data from the CI application object.
#3

[eluser]Mark75[/eluser]
Thank you for your fast reply!

Now my Controller looks like this:
Code:
class Public_Controller extends Controller {

    var $data;

    function Public_Controller()
    {
        parent::Controller();
        $this->data->user = $this->auth->get_user($this->session->userdata('user_id'));
    }

}
No errors, i hope that is the way you meant it.

Mark
#4

[eluser]wiredesignz[/eluser]
[quote author="Mark75" date="1243268621"]No errors, i hope that is the way you meant it.[/quote]

Yes and no.

Yes the var needs to be defined But...

You refer to the $data variable as an object ($this->data->user) but in fact you define it as a simple variable and PHP covers your ass by casting for you.

If $data is not really an object then it should be used as an array. ($this->data['user'])
#5

[eluser]Mark75[/eluser]
Ok, thanks for clarification. This should be better: (?)

Code:
class Public_Controller extends Controller {

    var $data = array();

    function Public_Controller()
    {
        parent::Controller();
        $this->data['user'] = $this->auth->get_user($this->session->userdata('user_id'));
        $this->data['settings'] = $this->model_settings->get_settings();
    }

}

Regards
Mark
#6

[eluser]Mark75[/eluser]
Hi again,
it would be great if you could help me one more time with a small problem...

My Public_Controller (in MX_Controller.php) now look like this:

Code:
class Public_Controller extends Controller {

    var $data;

    function Public_Controller()
    {
        parent::Controller();

        $this->data = array(
            'user' => $this->auth->get_user($this->session->userdata('user_id')),
            'settings' => $this->model_settings->get_settings()
            );

        $this->output->enable_profiler(TRUE);
    }

}
I modified the Profiler.php to display the data-Array, but when i load my page the Profiler cannot find my data-Variable:
Code:
Undefined property: CI::$data

Any help is greatly appreciated.
Thanks
mark
#7

[eluser]Mark75[/eluser]
Sorry for posting again, but i'm still fighting with the same problem (see post above).

$this->data is available in my view files without problem, but Profiler.php says
Code:
Undefined property: CI::$data
Normally, it should be there after
Code:
$this->CI =& get_instance();
or am i wrong?

Thanks for any hints.

Regards
Mark
#8

[eluser]wiredesignz[/eluser]
When using Modular Extensions 5.2 the controller and CI are separate objects so the profiler (using CI) will not see a controller class variable unless you specifically pass a reference.

Maybe something like this in your controller constructor
Code:
CI::instance()->data =& $this->data;
#9

[eluser]Mark75[/eluser]
Ok, that works. Thank you!
#10

[eluser]Unknown[/eluser]
good eve
I have a similar problem
I get this errors

A PHP Error was encountered

Severity: Notice

Message: Undefined property: CI::$data

Filename: libraries/Controller.php

Line Number: 354


public function __get($var) {
return CI::$APP->$var;

}
}



and

A PHP Error was encountered

Severity: Notice

Message: Indirect modification of overloaded property Bs::$data has no effect

Filename: controllers/bs.php

Line Number: 41

function add(){
$this->load->library('form_validation');
$this->data['custom_error'] = '';


the lines of codes are below. please anyone of help I am using codeigniter 1.7.2 and I got the codes for crud generator which was created with codeigniter 2.0.2




Theme © iAndrew 2016 - Forum software by © MyBB