luca
luca

Reputation: 37136

Zend are view variable available inside view helpers?

I am wondering if Zend view variables are available in my view helper class without passing them in directly as parameters

thanks

Luca

Upvotes: 4

Views: 3437

Answers (4)

ARIF MAHMUD RANA
ARIF MAHMUD RANA

Reputation: 5166

I found that when I set the view instance in registry and get it from helper the view variables stays. Here is a code snippet I used in my social engine project

$view = Zend_Registry::get('Zend_View');
/*
 * Check data available and set it to local variable
 */
if(isset($view->localeTranslations[$key]))
{
   $translate = $view->localeTranslations[$key];
}

Upvotes: 0

Xerkus
Xerkus

Reputation: 2705

You should know one thing:
view helper's view instance is the one set on helper instantiation It is not updated on view cloning. So you can't say for sure which one you're using if called from partial for example.

Upvotes: 1

tawfekov
tawfekov

Reputation: 5122

well you can access $view form inside the view helper , i will give an example : in the example below you can set and get view vars

<?php

class App_View_Helper_Job extends Zend_View_Helper_Abstract {

    public function setView(Zend_View_Interface $view) {
        $this->view = $view;
    }

    public function job() {
           $this->view->var1 = "testing var1 ";
           $this->view->var2 = $this->view->var1;
    }
}

Upvotes: 1

Phil
Phil

Reputation: 164762

As all view helpers have reference to the view in their $view property, the answer is yes.

What you won't know from the helper side is which properties are available. It would be better to pass any required properties to the helper at call or construction time.

Upvotes: 6

Related Questions