0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

zf2でのルーティング設定

0
Last updated at Posted at 2016-05-28

Zendframework2 ルーティング設定

以下のように'home'の中身を書き換える。

module.config.php

return array(
    'router' => array(
        'routes' => array(
            'home' => array(
                'type' => 'Segment',
                'options' => array(
                    'route'    => '/[:controller[/:action]]',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Application\Controller',
                        'controller' => 'Index',
                        'action'     => 'index',
                    ),
                ),
            ),

説明

■ 'type' => 'Segument'
Segmentにすると、controllerとactionを、リクエスト時のそれとマッピングさせることができる
例)http://domain/user/add userコントローラーのaddアクションが呼び出される
http://domain/member/add  memberコントローラーのaddアクションが呼び出される

一方、Literal(リテラル)というものがある。
これは、直接の意味合いをもつため、コントローラーとアクションを、作ったもを固定直接指定するようなイメージ。
リクエストとコントローラーが1対1であるようなイメージ。

なお、リテラル とは
a = 1 + 1 --> これは「式」と呼ばれるが
1+1の結果を直接2として指定すること、つまりa=2とするのが「リテラル」

'options'の'route'
[]は省略可能なことをあらわす

'options'の'defaults'
たとえば上記の設定でhttp://domain/と呼ばれた場合、
Indexコントローラーのindexアクションがデフォルトで呼ばれる

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?