1

ZF2 SkeletonAppbaseでWebアプリを開発しています。私は多くのオプションで遊んできましたが、最終的な前進を得ることができませんでした。

以下のようにURLをルーティングする必要があります:

http://myapp/
http://myapp/en/album

AlbumController/indexActionに。また、リンクは次のように機能する必要があります。

http://myapp/en/album/edit/1
http://myapp/en/album/delete/1

コードは正しいURLを生成しますが、クリックすると「404」エラーが返されます

私のApplication/module.config.phpは以下のとおりです。


return array (
        'router' => array (
                'routes' => array (
                        'home' => array (
                                'type' => 'Zend\Mvc\Router\Http\Literal',
                                'options' => array (
                                        'route' => '/',
                                        'defaults' => array (
                                                'controller' => 'Album\Controller\Album',
                                                'action' => 'index',
                                                'lang'     => 'en',
                                        ) 
                                ) 
                        ),
                        'application' => array (
                                'type' => 'Literal',
                                'options' => array (
                                        'route' => '/application',
                                        'defaults' => array (
                                                '__NAMESPACE__' => 'Application\Controller',
                                                'controller' => 'Index',
                                                'action' => 'index' 
                                        ) 
                                ),
                                'may_terminate' => true,
                                'child_routes' => array (
                                        'default' => array (
                                                'type' => 'Segment',
                                                'options' => array (
                                                        'route' => '[:lang[/album[/:action[/:id]]]]',
                                                        'constraints' => array (
                                                                'lang'     => '[a-z]{2}',
                                                                'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                                                'id' => '[0-9]+'
                                                        ),
                                                        'defaults' => array (
                                                                'controller' => 'Album\Controller\Album',
                                                                'action' => 'index',
                                                                'lang'     => 'en',
                                                        )
                                                ) 
                                        ) 
                                ) 
                        ) 
                ) 
        ),
        '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 (
                        'Application\Controller\Index' => 'Application\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/layout' => __DIR__ . '/../view/layout/layout.phtml',
                        'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
                        'error/404' => __DIR__ . '/../view/error/404.phtml',
                        'error/index' => __DIR__ . '/../view/error/index.phtml' 
                ),
                'template_path_stack' => array (
                        __DIR__ . '/../view' 
                ) 
        ) 
);

私のAlbum/module.config.phpには次のルーターがあります。


'router' => array (
                'routes' => array (
                        'album' => array (
                                'type' => 'segment',
                                'options' => array (
                                        'route' => '[:lang[/album[/:action[/:id]]]]',
                                        'constraints' => array (
                                                'lang'     => '[a-z]{2}',
                                                'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                                'id' => '[0-9]+'
                                        ),
                                        'defaults' => array (
                                                'controller' => 'Album\Controller\Album',
                                                'action' => 'index', 
                                                'lang'     => 'en',
                                        )
                                ),
                        )
                )
        ), 

////////////////////////////////////////////////// ////////////////////////////////////////これで正常に動作します。

また、$ this-> url('album'、array('action' =>'edit'、'id' => $ album-> id));を呼び出すと ビューファイル(.phtml)では、期待どおりに適切なURLが返されません。

http://www.myapp.com/en/edit/id/1

////////////////////////////////////////////////// ///////////////////////////////////////////修正されたコードはURL$this->urlで機能します('album'、array('action' =>'edit'、'id' => $ album-> id))////////////////////// ////////////////////////////////////////////////// ///////////////

事前にあなたの助けに感謝します。

4

1 に答える 1

1

この問題は、Album/module.config.phpに「/」がありませんでした。

'route' => '[:lang[/album[/:action[/:id]]]

になるはずだった:

'route' => '/[:lang[/album[/:action[/:id]]]

助けてくれてありがとう。

于 2013-01-23T11:12:51.000 に答える