CodeIgniter Forums
how to access class data member from a hook file? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: how to access class data member from a hook file? (/showthread.php?tid=34419)



how to access class data member from a hook file? - El Forum - 09-29-2010

[eluser]prestondocks[/eluser]
Hi, I have defined a hook file for which I want to access and a data member in the class being called.

The code in my hook file looks like this
Code:
class Security
{

function module_permission()
{
$CI =& get_instance();
$class = $CI->router->class;
$method = $CI->router->method;
echo $CI->$class->sec_test;
}
}

But I am getting the following error

Code:
A PHP Error was encountered
Severity: Notice

Message: Undefined property: CI::$meetings

Filename: hooks/security.php

Line Number: 11

A PHP Error was encountered
Severity: Notice

Message: Trying to get property of non-object

Filename: hooks/security.php

Line Number: 11

I am using the post_controller_constructer hook

I am also using HMVC

Can anyone help me to solve this issue?

Thanks for any help,


how to access class data member from a hook file? - El Forum - 09-29-2010

[eluser]Dennis Rasmussen[/eluser]
Where is the variable $meetings defined?


how to access class data member from a hook file? - El Forum - 09-29-2010

[eluser]prestondocks[/eluser]
$meetings is not a variable. I am using $class as the variable, which has the value of "meetings" taken from $CI->router->class.

Your question did make me realise that class is a reserved name, but even after changing this variable to $called_class rather than $class, I get the same error.


how to access class data member from a hook file? - El Forum - 09-29-2010

[eluser]Dennis Rasmussen[/eluser]
Okay but the reason I'm asking is because the error says that the property CI->$meetings isn't defined.
So you need to make sure it's defined or not call it at all.


how to access class data member from a hook file? - El Forum - 09-29-2010

[eluser]InsiteFX[/eluser]
Also I would change the name of your class because CodeIgniter 2.0
has a Security class!

InsiteFX