how to show data from document to index.phtml in zf2?

后端 未结 1 1840
面向向阳花
面向向阳花 2021-01-26 10:29

i make index action in which i want to get data of calender and show this data using index.phtml but always no calendar shown,how i show calendar data? here is my indexaction:

1条回答
  •  攒了一身酷
    2021-01-26 11:20

    You need a view model to render your data. Instead of

    return array('calendars' => $calendars);
    

    You want this for a View:

    $viewModel  =   new ViewModel
                        (
                            array
                            (
                                'calendars' =>  $calendars,
                            )
                        );
    
    return $viewModel;
    

    or this for Json:

    $jsonModel  =   new JsonModel
                (
                array
                (
                    'calendars' =>  $calendars,
                                )
                );
    
    return $jsonModel;
    

    make sure to add the use statements for your controller:

    use Zend\View\Model\ViewModel;
    use Zend\View\Model\JsonModel;
    

    If you want to specify a specific view you can use:

    $viewModel->setTemplate('path/to/specific/view.phtml');
    

    or

    $viewModel->setTemplate('mapping/for/specifc/view');
    

    with the mapping specified in your module config

    0 讨论(0)
提交回复
热议问题