SOLVED; auth using my_controller |
[eluser]Slowcheetah[/eluser]
Hi, i'm fairly new with extending classes. Now i'm a bit experimenting with this, i have a question. I want to protect functions with a simple command.. something like the code below. Code: class Welcome extends MY_Controller { In my extended controller i have the following code. Code: class MY_Controller extends CI_Controller { It gives the following error; Code: Message: Undefined property: Welcome::$auth What i'm doing wrong?
[eluser]4ever[/eluser]
I guess you are trying to access property which does not exist. write something like Code: class Welcome extends MY_Controller { Or you should to reference the previous controller property but I know know how to do this
[eluser]danmontgomery[/eluser]
You're trying to access those variables before they're ever defined. Your code is executed as: - Welcome object instantiated - Welcome::__construct() called - MY_Controller::__construct() called via parent::__construct() ( variables checked ) - Welcome::index() called ( variables created ) If you want to set access control in the method, you would need to run the check after the method has executed. You could do this with a post_controller hook, or define the method access in the constructor of Welcome, before parent::__construct() is called.
[eluser]Slowcheetah[/eluser]
@noctrum Thanks! i have it working now. I never worked with the hooks before this. Looks promising. |
Welcome Guest, Not a member yet? Register Sign In |