0

Trying to get the view object from a view helper so I can render a certain partial. but All I get is NULL here is the code namespace App\Form\View\Helper;

use Zend\Form\View\Helper\AbstractHelper;
use Zend\Form\View\Helper\FormInput;
use Zend\Form\ElementInterface;
class FormDate2 extends AbstractHelper
{
    protected $script = 'element-decorators/date-picker';

    public function render(ElementInterface $element, $formType = null, array $displayOptions = array())
    {
        echo '<pre>';var_dump($this->getView());echo '</pre>';die();
    }
}
Omar
  • 8,374
  • 8
  • 39
  • 50
  • 1
    How are you testing the helper to determine that the view object is null? – Crisp May 13 '13 at 11:43
  • Custom Element using that helper – Omar May 13 '13 at 12:29
  • The process is as follows, a FormRow Helper renders the element view parts, and getting the element html through the element's helper which is the one posted above – Omar May 13 '13 at 12:31

1 Answers1

1

Found a solution, Not sure if it is the best one, If anyone got a better one please post above

Here it goes, retrieve the view renderer from the Di

    public function __construct()
    {
        if($this->getView() == NULL){
            $di = new Di();
            $view = $di->get('Zend\View\Renderer\PhpRenderer');
            $this->setView($view);
        }
    }
Omar
  • 8,374
  • 8
  • 39
  • 50