0

機能しないルートがいくつかありますが、他のすべてが機能するため、理由がわかりません。ここでは私の module.config.php :

return array(
'controllers' => array(
    'invokables' => array(
        'FrontApp\Controller\Index' => 'FrontApp\Controller\IndexController',
        'FrontApp\Controller\User' => 'FrontApp\Controller\UserController',
    ),
),


'router' => array(
    'routes' => array(
        'confirm' => array(
            'type'    => 'Literal',
            'options' => array(
                'route'    => '/confirm',
                'defaults' => array(
                    'controller' => 'FrontApp\Controller\Index',
                    'action'     => 'confirm',
                ),
            ),
        ),
        'user' => array(
            'type'    => 'Literal',
            'options' => array(
                'route'    => '/connexion',
                'defaults' => array(
                    'controller' => 'FrontApp\Controller\User',
                    'action'     => 'index',
                ),
            ),
        ),
        'detail' => array(
            'type'    => 'Segment',
            'options' => array(
                'route'    => '/:type/:location/:id',
                'constraints' => array(
                    'type'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'location' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'id'       => '[0-9]+',
                ),
                'defaults' => array(
                    'controller' => 'FrontApp\Controller\Index',
                    'action'     => 'detail',
                ),
            ),
        ),
        'search' => array(
            'type'    => 'Segment',
            'options' => array(
                'route'    => '/:type[/:location]',
                'constraints' => array(
                    'type'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'location' => '[a-zA-Z][a-zA-Z0-9_-]*',
                ),
                'defaults' => array(
                    'controller' => 'FrontApp\Controller\Index',
                    'action'     => 'search',
                ),
            ),
        ),
        'front' => array(
            'type'    => 'Literal',
            'options' => array(
                'route'    => '/',
                'defaults' => array(
                    'controller' => 'FrontApp\Controller\Index',
                    'action'     => 'index',
                ),
            ),
        ),
    ),
),

'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/front-layout.phtml',
        'layout/frontlayout'           => __DIR__ . '/../view/layout/front-layout.phtml',
        'frontapp/index/index' => __DIR__ . '/../view/front-app/index/index.phtml',
        'error/404'               => __DIR__ . '/../view/error/404.phtml',
        'error/index'             => __DIR__ . '/../view/error/index.phtml',
    ),
    'template_path_stack' => array(
        'front' => __DIR__ . '/../view',
        'searcher' => __DIR__ . '/../view',
        'detail' => __DIR__ . '/../view',
        'user' => __DIR__ . '/../view',
        'confirm' => __DIR__ . '/../view',
    ),
),
'module_layouts' => array(
        'FrontApp' => 'layout/frontlayout',
        'BackApp' => 'layout/backlayout',
),);

だから私がしようとすると:

mywebsite/ -> 仕事

mywebsite/one-type -> 仕事

mywebsite/one-type/one-location -> 動作しません

mywebsite/one-type/one-location/on-id -> 動作しません

mywebsite/connexion ->仕事

mywebsite/confirm -> 仕事

異なるルートタイプを使用できないように、少し混乱しています。したがって、機能しないルートについては、「....テンプレートをレンダリングできません」というエラーが発生し、「レイアウト/レイアウト...」というエラーが発生します。これは、「レイアウト/フロントレイアウト」と同じパスで「レイアウト/レイアウト」を追加すると解決されます' template_map キー (私も理由はよくわかりませんが、機能するので、教えていただければ幸いです)、または「要求された URL をルーティングで一致させることができませんでした。」およびこのエラーについて、どこに問題があるのか​​ わからないので行き詰まっています:/

あなたが助けてくれることを願っています:)

4

1 に答える 1

0

ここで答え:

'routes' => array(
'search' => array(
    'type'    => 'Segment',
    'options' => array(
        'route'    => '/:type[/:location]',
        'constraints' => array(
            'type'     => '[a-zA-Z][a-zA-Z0-9_-]*',
            'location' => '[a-zA-Z0-9_-]*',
        ),
        'defaults' => array(
            'controller' => 'FrontApp\Controller\Index',
            'action'     => 'search',
        ),
    ),
    'may_terminate' => true,
    'child_routes' => array(
        'detail' => array(
            'type'    => 'Segment',
            'options' => array(
                'route'    => '/:id',
                'constraints' => array(
                    'id' => '[0-9]+',
                ),
                'defaults' => array(
                    'action' => 'detail',
                ),
            ),
        ),
    ),
),
'confirm' => array(
    'type'    => 'Literal',
    'options' => array(
        'route'    => '/confirm',
        'defaults' => array(
            'controller' => 'FrontApp\Controller\Index',
            'action'     => 'confirm',
        ),
    ),
),
'user' => array(
    'type'    => 'Literal',
    'options' => array(
        'route'    => '/connexion',
        'defaults' => array(
            'controller' => 'FrontApp\Controller\User',
            'action'     => 'index',
        ),
    ),
),
'front' => array(
    'type'    => 'Literal',
    'options' => array(
        'route'    => '/',
        'defaults' => array(
            'controller' => 'FrontApp\Controller\Index',
            'action'     => 'index',
        ),
    ),
),

)、

リテラル ルートは後でプッシュされるため、最上位セグメントを定義するセグメント ルートの前にそれらが一致することを確認する必要がありました。

「検索」ルートと「詳細」ルートを組み合わせて、「詳細」を「検索」の子ルートにしました。これにより、場所も存在しない限り、ルーターが識別子を照合しようとしなくなります。これにより、マッチングが高速化され、定義がわずかにスリムになります。

単語や数字を受け入れるように、場所の制約の正規表現を変更しました。

于 2013-08-19T11:42:30.747 に答える