Passing part of the $data array in the constructor |
[eluser]Media Gearhead[/eluser]
I am trying to optimize my code and when loading views I am passing a data array. Code: class Auth extends Controller { What I would like to do is something like this where any parts of the $data array that are the same on all parts of this controller are put in one location in the controller instead of copying it into every function but I am not able to figure it out. Code: class Auth extends Controller { I am getting variable non-existent errors after I am loading the view. I am thinking it has to do with the scope of the variables but I am not finding the right setup to make it work. Thank you for any help.
[eluser]n0xie[/eluser]
Make it a class property: Code: // change You might want to take a look at Base Classes for an even better approach
[eluser]Media Gearhead[/eluser]
I love the idea. Unfortunately it is saying undefined variable. How can I instantiate the variable so that I can use it? I am assuming something after the class is created. Code: class Auth extends Controller { I am new to OOP and variable scope is one thing that is kicking me while down.
[eluser]Buso[/eluser]
as noxie said, use $this->data Code: class Auth extends Controller {
[eluser]Media Gearhead[/eluser]
That is what I tried. This is the exact code I am using now. I had sent a simpler chunk of code to streamline the functionality I am trying to use. Code: <?php It fails at line 10 with these errors. Code: A PHP Error was encountered
[eluser]Media Gearhead[/eluser]
I ask for help and I cannot even read things as written without getting it wrong... Kicking myself has already commenced and will continue for a few hours. Thank you to all as all is working as I was hoping to get for the end result. |
Welcome Guest, Not a member yet? Register Sign In |