arrayszend-frameworkzend-framework2zend-view

Get Array Element in Zend View


i pass an array to my view and i can't show element in my view ! THis is my array : Array ( [pin] => 00000 [card] => 00000 [status] => Y). thnx for helping me .


Solution

  • suppose you have array

     $arrayData = array ( 'pin' => 00000, 'card' => 00000, 'status' => Y);
    
    $viewModel = new \Zend\View\Model\ViewModel();
    
    $viewModel->setVariables($arrayData);
    

    Now, on view you can directly access as-

    $pin, $card, etc
    

    this will add a single varibale to the view-

     $viewModel->setVariable('testVar', 'abc');
    

    on view page, just use as

     $testVar;