Elsewhere I posed a thought a about automatically assigning variables
to the view within the Action Controller and it was said that this
might not be compatible either with ZF 2.0 or the way that Action
Helpers interact with contoller variables.

However I'm still unsure as why in the case of Action Helpers this
might be a problem.

The following is what I had in mind:

        public function &__get($key) {
                if ('_' === substr($key, 0, 1)  || !isset($this->_data[$key])) {
                        trigger_error('Key "'.$key.'" does not exist', 
E_USER_NOTICE);
                        $result = null;
                        return $result;
                }

                return $this->_data[$key];
        }

        public function __set($key, $value)
    {
                if ('_' === substr($key, 0, 1)) {
                        throw new VF_Exception('Setting ... is not allowed');
                }

                $this->_data[$key] = $value;
        if (isset($this->view)) {
            $this->view->assign($key, $value);
        }
        }

Although not 100% elegant, it does present a means  to working around
when two action methods then have to handle view variable assignment
(generally for the same view script).

Otherwise some common method would need to be available to the Action
Controller?

I'm running into two types of cases of view variable assignments:

[1] Those that are actually used by the Controller, e.g form
[2] Supplementary data used within the view script.

For [2] I'm thinking this could/should probably be handled by a View
Helper instead.

It would be great to know how others are handling their view variable
assignments prior to view script being rendered. Or there are any
problems perceived with using the magic methods above.?

Thanks,

Reply via email to