austenc's avatar

Access View Variable in Outside Class

Hello, I'm trying to override the base Form class to add some additional functionality for disabling fields... I'm a bit stuck on how to access view variable(s) in my class since it's outside the scope of the view/controller lifecycle. Here's what I've got:

<?php namespace Acme;

class Form extends \Illuminate\Html\FormBuilder {
    // Checks if the session param for disabling fields has been set
    private function disableFields($options = array()) {
        if (\Session::has('disableFields') 
            && \Session::get('disableFields') === true 
            && (is_array($options) && ! in_array('disabled', $options)))
        {
            return true;   
        }

        return false;
    }
}

And when I make the view in the controller I've got something like View::make('myview')->with(['disableFields' => true])

Now, sometimes the view var is set in the session, but sometimes (on a regular get request for instance), the view vars aren't in the session -- so I'll need to check both places in my if statement... but how would I go about accessing view variables in my class? Note this is Laravel 4.2, but all answers welcome! Is there a way to do it with an $app instance or some other way to get the current view vars for a request?

0 likes
0 replies

Please or to participate in this conversation.