Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
776 views
in Q2A Core by
I am using an advanced theme to override two functions:

1. function main()

2. function q_view($q_view)

In main() I am also checking some user information, like is logged in and more! Then I set a boolean variable in main().

This boolean variable I need to access now from within q_view(), without doing all the queries again that I did in main().

How would you do that?

Thanks and have a good weekend,
Kai
by
I tried to declare a global variable in advanced theme:

private $globalHelper = false;

and set this in main() to true,
then I tried to read it in q_view(),
which resulted in: "Error: Undefined variable"

2 Answers

+1 vote
by
edited by
 
Best answer

All right, here is an example how it is gonna work:

class qa_html_theme extends qa_html_theme_base {

    var $globalHelper = false;

    function main() {

       // default code

        $this->globalHelper = true;

    }

    function q_view($q_view) {

       if ($this->globalHelper ) {

            // ..

        }

    }

} // end class

 

Note that in $this->globalHelper  $globalHelper has no dollar sign in front anymore!

+1 vote
by
Please read here:

 

http://www.question2answer.org/qa/12235/how-to-use-variable-again-php-question?show=12235#q12235

 

Would be great if You could post an example if You figure it out finally. I still have problems with this.
by
Thanks, that helped me! Example with explanation will be posted here in a moment :)
...