1

Zend Framework 2でデフォルトのモジュールを変更する方法を知っている人はいますか?スケルトンアプリケーションをホームページとして使用していますが、デフォルトのホームページを持つ別のモジュールを作成したいと思います。私は2つのことを試しました

application.config.phpファイルから「SkeletonApplication」を削除しました。これは次のようになります。

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',
     ),
   ),
);

モジュールから「アプリケーション」を削除したことがわからない場合は、Helloworldモジュールのmodule.config.phpファイルを変更しました。以前は次のようになりました。

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'
      )
   )
);

options=>routeの「router」配列に変更が加えられました。値を「/」に変更しました。

しかし、それは5000エラーをスローします。誰かが私が間違っていることについて詳しく説明できますか?

4

2 に答える 2

0

OK、アプリケーションに問題がありました。ルーティングは実際には正しいです。問題は、モジュール構成でこれらすべてを指定するために必要な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',
    ),
)
于 2012-12-19T20:08:11.360 に答える
0

ホームルートのアプリケーションモジュール(myproject / module / application / config / module.config.php)のmodule.config.phpにurlを設定することで、プロジェクトのホームページを設定できます。たとえば、デフォルトモジュールのインデックスコントローラのインデックスアクションをホームページとして使用する場合は、上記のファイルのホームルートを変更する必要があります。すなわち

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

上記のコードを使用する前に、必ず(myproject / config / application.config.php)で新しいモジュールを定義してください。さらにサポートが必要な場合はお知らせください。ありがとう..:)

于 2014-06-13T05:28:29.113 に答える