2013-02-03 146 views
0

我正在嘗試學習Zend Framework 2並且目前正面臨一個問題。基於ZF2模塊的佈局

我創建了一個名爲「Admin」的模塊,併爲Admin Module定義了佈局。現在的問題是Application模塊也在加載管理模塊的佈局。如果我瀏覽管理員或應用程序模塊,則正在加載相同的佈局。我試過谷歌搜索多種解決方案,但沒有得到任何人的工作。

我已經通過複製應用程序模塊目錄並將其重命名爲Admin並將子目錄名稱和代碼文件中的「Application」更改爲「Admin」來創建Admin模塊。

+5

2秒鐘的谷歌> https://github.com/EvanDotPro/EdpModuleLayouts – Sam

回答

0

那麼,最後我找到了一個解決方案。

假設你想創建一個名爲「管理」模塊,這裏的步驟:

1複製應用模塊迪爾並將其重命名爲「管理員」。這是你的模塊的名字。

2-更新管理模塊中最初指向應用程序模塊的所有引用。 (將「應用程序」更改爲「應用程序」,將「應用程序」更改爲「管理員」)

3-在Admin/config/module.config.php中刪除「home」路由。

4-更新您的佈局和視圖。

5使用http://example.com/admin

這就是它在瀏覽器中測試。

你並不需要像「EdpModuleLayouts」

乾杯:)

1

這是Khalids後與在config/application.config.php文件多了一個另外的視覺呈現任何外部佈局的lib 步驟1. 步驟2. 複製應用模塊並重新命名爲Admin

//config/application.config.php 
    'modules' => array(
      'Application' 
      ,'Test', // add this line 
     ), 




<?php 
//Step 3. 

//你的測試/配置/ module.config.php應該像下面

return array(
    'router' => array(
     'routes' => array(
      /* 'home' => array(
       'type' => 'Zend\Mvc\Router\Http\Literal', 
       'options' => array(
        'route' => '/', 
        'defaults' => array(
         // 'controller' => 'StickyNotes\Controller\Album', 
         //'controller' => 'Application\Controller\Index', 
         'action'  => 'index', 
        ), 
       ), 
      ), */ 
      // The following is a route to simplify getting started creating 
      // new controllers and actions without needing to create a new 
      // module. Simply drop new controllers in, and you can access them 
      // using the path /application/:controller/:action 
      'application' => array(
       'type' => 'Literal', 
       'options' => array(
        'route' => '/test', 
        'defaults' => array(
         '__NAMESPACE__' => 'Test\Controller', 
         'controller' => 'Index', 
         'action'  => 'index', 
        ), 
       ), 
       'may_terminate' => true, 
       'child_routes' => array(
        'default' => array(
         'type' => 'Segment', 
         'options' => array(
          'route' => '/[:controller[/:action]]', 
          'constraints' => array(
           'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 
           'action'  => '[a-zA-Z][a-zA-Z0-9_-]*', 
          ), 
          'defaults' => array(
          ), 
         ), 
        ), 
       ), 
      ), 
     ), 
    ), 
    'service_manager' => array(
     'factories' => array(
      'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory', 
     ), 
    ), 
    'translator' => array(
     'locale' => 'en_US', 
     'translation_file_patterns' => array(
      array(
       'type'  => 'gettext', 
       'base_dir' => __DIR__ . '/../language', 
       'pattern' => '%s.mo', 
      ), 
     ), 
    ), 
    'controllers' => array(
     'invokables' => array(
      'Test\Controller\Index' => 'Test\Controller\IndexController', 

     ), 
    ), 
    'view_manager' => array(
     'display_not_found_reason' => true, 
     'display_exceptions'  => true, 
     'doctype'     => 'HTML5', 
     'not_found_template'  => 'error/404', 
     'exception_template'  => 'error/index', 
     'template_map' => array(
      'layout/test'   => __DIR__ . '/../view/layout/test.phtml', 
      'application/index/index' => __DIR__ . '/../view/test/index/index.phtml', 
      'error/404'    => __DIR__ . '/../view/error/404.phtml', 
      'error/index'    => __DIR__ . '/../view/error/index.phtml', 
     ), 
     'template_path_stack' => array(
      __DIR__ . '/../view', 
     ), 
    ), 
); 

步驟4. 最後是你的測試/模塊文件應如下所示: - >

namespace Test; 

use Zend\Mvc\ModuleRouteListener; 
use Zend\Mvc\MvcEvent; 

class Module 
{ 
    public function onBootstrap(MvcEvent $e) 
    { 
     $e->getApplication()->getServiceManager()->get('translator'); 
     $eventManager  = $e->getApplication()->getEventManager(); 
     $moduleRouteListener = new ModuleRouteListener(); 
     $moduleRouteListener->attach($eventManager); 
    } 

    public function getConfig() 
    { 
     return include __DIR__ . '/config/module.config.php'; 
    } 

    public function getAutoloaderConfig() 
    { 
     return array(
      'Zend\Loader\StandardAutoloader' => array(
       'namespaces' => array(
        __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, 
       ), 
      ), 
     ); 
    } 
} 

,你將準備推出。