Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

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.



  • Options
    hgtonighthgtonight ∞ · New Moderator
    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.