2012-12-19 52 views
1

任何人都知道如何在Zend Framework 2中更改默認模塊?我使用骨架應用程序作爲主頁,但我想創建另一個模塊,使其具有默認主頁。 我想兩件事情如何在Zend Framework 2中爲默認模塊製作自定義模型

我刪除從application.config.php文件中的「框架應用程序」這是它看起來像

return array(
'modules' => array(
    'Application', 
    'Helloworld' 
), 
'module_listener_options' => array(
    'config_glob_paths' => array(
     'config/autoload/{,*.}{global,local}.php', 
    ), 
    'module_paths' => array(
     './module', 
     './vendor', 
    ), 
), 
); 

這是它看起來像現在

return array(
'modules' => array(
    'Helloworld' 
), 
'module_listener_options' => array(
    'config_glob_paths' => array(
     'config/autoload/{,*.}{global,local}.php', 
    ), 
    'module_paths' => array(
     './module', 
     './vendor', 
    ), 
    ), 
); 

如果你不能告訴我從模塊 刪除'應用程序'然後我改變了我的module.config.php文件的Helloworld模塊 這裏是它看起來像

return array(
'view_manager' => array(
    'template_path_stack' => array(
     __DIR__ . '/../view', 
    ), 
), 
'router' => array(
    'routes' => array(
     'sayhello' => array(
      'type' => 'Zend\Mvc\Router\Http\Literal', 
      'options' => array(
       'route' => '/sayhello', 
       'defaults' => array(
        'controller' => 'Helloworld\Controller\Index', 
        'action' => 'index', 
       ) 
      ) 
     ) 
    ) 
), 
'controllers' => array(
    'factories' => array(
     'Helloworld\Controller\Index' => 'Helloworld\Controller\IndexControllerFactory' 
    ) 
), 
'service_manager' => array(
    'invokables' => array(
     'greetingService' => 'Helloworld\Service\GreetingService' 
    ) 
    ) 
); 

這是它看起來像現在

return array(
'view_manager' => array(
    'template_path_stack' => array(
     __DIR__ . '/../view', 
    ), 
), 
'router' => array(
    'routes' => array(
     'sayhello' => array(
      'type' => 'Zend\Mvc\Router\Http\Literal', 
      'options' => array(
       'route' => '/', 
       'defaults' => array(
        'controller' => 'Helloworld\Controller\Index', 
        'action' => 'index', 
       ) 
      ) 
     ) 
    ) 
), 
'controllers' => array(
    'factories' => array(
     'Helloworld\Controller\Index' => 'Helloworld\Controller\IndexControllerFactory' 
    ) 
), 
'service_manager' => array(
    'invokables' => array(
     'greetingService' => 'Helloworld\Service\GreetingService' 
    ) 
    ) 
); 

的變化是在選項的「路由器」陣列製成=>路線,我改變了價值,只是「/」

但它會拋出一個5000錯誤 任何人都可以詳細說明我做錯了什麼?

+0

現在我記得爲什麼我切換到Symfony ... – mpm

+0

你是否已將'Application'文件夾更名爲'src'文件夾中的'Helloworld'?它必須解決你的路由問題 – tawfekov

+0

謝謝你的回覆。我想我只是不明白如何模板默認工作,他們基本上級聯。這就是爲什麼我沒有在我的Hello World中創建佈局而離開的原因,只要「骨架應用程序」在那裏也可以工作。 –

回答

0

好吧,我看到了我的應用程序的問題。路由實際上是正確的問題是我缺少一個layout.phtml文件,我需要在模塊配置中指定所有這些。我需要將以下添加到我的module.config.php

'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/layout'   => __DIR__ . '/../view/layout/layout.phtml', 
     'valaree/index/index' => __DIR__ . '/../view/valaree/index/index.phtml', 
     'error/404'    => __DIR__ . '/../view/error/404.phtml', 
     'error/index'    => __DIR__ . '/../view/error/index.phtml', 
    ), 
    'template_path_stack' => array(
     __DIR__ . '/../view', 
    ), 
) 
0

您可以通過在應用模塊 (myproject的/模塊/應用/配置/模塊的module.config.php設置URL設置你的項目主頁.config.php)在本地路由。例如,如果要使用默認模塊的索引控制器的索引動作作爲主頁,則需要更改上述文件中的主路由。即

 'home' => array(
      'type' => 'Zend\Mvc\Router\Http\Literal', 
      'options' => array(
       'route' => '/', 
       'defaults' => array(
        'controller' => 'Default\Controller\Index', 
        'action'  => 'index', 
       ), 
      ), 
     ), 

在使用上述代碼之前,請確保您在(myproject/config/application.config.php)中定義了您的新模塊。請讓我知道你是否需要任何進一步的幫助。謝謝.. :)

相關問題