1

我在我的模块 Admin/view/layout/dashboard.phtml 中开发了dashboard.phtml

现在我已经开发了另一个模块,比如餐厅,现在我想在下面尝试的重新启动模块的所有操作中使用 dashboard.phtml。

我的 module.config.php

 'view_manager' => array(
    'template_map' => array(
        'layout/default' => __DIR__ . '/../../Admin/view/layout/dashboard.phtml'
    ),
    'template_path_stack' => array(
        'restaurants' => __DIR__ . '/../view',

    ),

我对restaurantController.php 的索引操作

public function indexAction()
{

   $viewModel = new ViewModel();
   $viewModel->setTemplate('layout/default');
   $restaurant_info_array = array();
   $restaurant_info = $this->getRestaurantsTable()->fetchAll();
    $i = 0;
    foreach ($restaurant_info as $ri)
    {
        $restaurant_info_array[$i]['id'] = $ri->id;
        $restaurant_info_array[$i]['name'] = $ri->name;
        $restaurant_info_array[$i]['published'] = $ri->published;
        $restaurant_info_array[$i]['email'] = $ri->email;
        $is_menu_available = $this->getRestaurantsTable()->getRestaurantsMenu($ri->id);
        $restaurant_info_array[$i]['res_menu'] = count($is_menu_available);
        $i = $i+1;
    }

    $viewModel->setVariables(array(
            "restaurants"=>$restaurant_info_array
    ));

它不起作用请帮助我,如果我将仪表板称为我的管理端模块的默认布局,那将很棒,因为它不符合逻辑相同的仪表板.phtml 位于我模块的所有文件夹中。

4

1 回答 1

1

是的,我找到了解决方案,我在 module.php 中更改了我的代码,如下所示

public function onBootstrap(MvcEvent $e)
{ 
    $e->getApplication()->getServiceManager()->get('translator');
    $eventManager        = $e->getApplication()->getEventManager();
    $moduleRouteListener = new ModuleRouteListener();
    $moduleRouteListener->attach($eventManager);
   //added lines for layout
    $eventManager->getSharedManager()->attach('Zend\Mvc\Controller\AbstractActionController', 'dispatch', function($e) {
    $controller = $e->getTarget();
    $controller->layout('layout/default');
    });
}

我的 indexAction 的变化。

public function indexAction()
{
   $viewModel = new ViewModel();
   $restaurant_info_array = array();
   $restaurant_info = $this->getRestaurantsTable()->fetchAll();
   $i = 0;
   foreach ($restaurant_info as $ri)
   {
        $restaurant_info_array[$i]['id'] = $ri->id;
        $restaurant_info_array[$i]['name'] = $ri->name;
        $restaurant_info_array[$i]['published'] = $ri->published;
        $restaurant_info_array[$i]['email'] = $ri->email;
        $is_menu_available = $this->getRestaurantsTable()->getRestaurantsMenu($ri->id);
        $restaurant_info_array[$i]['res_menu'] = count($is_menu_available);
        $i = $i+1;
    }

    return $viewModel->setVariables(array(
            "restaurants"=>$restaurant_info_array
    ));

}
于 2012-12-12T12:54:24.523 回答