Vanilla open source was terminated 1 January 2025 by Higher Logic. See this announcement for more information.

Using a variable defined in controller inside a view

odannycodannyc New
edited February 2016 in Vanilla 2.0 - 2.8

Hey guys,

I come from using Laravel framework so using variables in a view are as easy as defining the variable in the controller and using it in the view.

But with Garden (vanilla) I'm having problems understanding how it works.
So in my controller I set a variable: $test = "testing var";

But when i try and do something like echo $test; in the view.. nothing shows up.

Can anyone guide me or tell me the logic behind this.

Tagged:

Comments

  • hgtonighthgtonight MVP
    edited February 2016

    Welcome to the community!

    There is a greater separation between controllers and views. Use the data methods to access information.

    In the controller:

    $this->setData('Key', 'value');
    

    In the view:

    $var = $this->data('Key'); // var contains 'value'
    

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

Sign In or Register to comment.