0

この方法でリダイレクトしています。私はこのように間違っていると思います。より良い方法を教えてください。

<a href="<?php echo $this->serverUrl()."/restaurantlist/view/".$list['id']."/".$list['name']?>">
   <img  alt="" src="<?php echo $image; ?>">
</a> 

私のmodule.config.phpのコード

<?php
 return array(
'controllers' => array(
    'invokables' => array(
        'Restaurantlist\Controller\Restaurantlist' => 'Restaurantlist\Controller\RestaurantlistController',
    ),

),

'router' => array(
    'routes' => array(
        'Restaurantlist' => array(
            'type'    => 'segment',

            'options' => array(
                // Change this to something specific to your module
                'route'    => '/restaurantlist[/]',

                'defaults' => array(
                    'controller' => 'Restaurantlist\Controller\Restaurantlist',
                    'action'     => 'list',
                ),
            ),

            'may_terminate' => true,
             'child_routes' => array(

                    'view' => array(
                        'type'    => 'Segment',
                        'options' => array(
                            'route'    => '[/]view[/:id][/:name][/]',
                            'constraints' => array(
                                'name' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'id'     => '[0-9]+',
                            ),
                            'defaults' => array(
                                'controller' => 'Restaurantlist\Controller\Restaurantlist',
                                'action'        => 'view',
                            ),
                        ),
                    ),


             ),
        ),
    ),
),
'view_helpers' => array(
    'factories' => array(
            'Requesthelper' => function($sm){
                $helper = new \Restaurantlist\View\Helper\Requesthelper;
                $request = $sm->getServiceLocator()->get('Request');
                $helper->setRequest($request);
                return $helper;
            }
    )
),
'view_manager' => array(
    'template_path_stack' => array(
        'Restaurantlist' => __DIR__ . '/../view',
    ),
),

);

http://test.localhost.com/restaurantlist/view/157/Bluestemのようにリダイレクトされ、 問題なく動作しますが、この http://test.localhost.com/Bluestem または http://test.localhost が 必要です。 com/157-ブルーステム

私はたくさん試しましたが、成功しませんでした。

4

2 に答える 2

2

最初に、目的のルートに一致するようにルートを変更しましょう。

'route'    => '/[:id]-[:name]',

次に、ビューでルートパスを使用して正しい URL を作成します。

echo $this->url('Restaurantlist/view', array('id' => $list['id'], 'name' => $list['name']));

また、小文字のルート名を使用することをお勧めします。

編集

先頭の/restaurantlistを取り除くには、その外側にビュールートを配置する必要があります。

'router' => array(
    'routes' => array(
        'restaurantlist-view' => array(
            'type'    => 'Segment',
            'options' => array(
                'route'    => '/[:id]-[:name]',
                'constraints' => array(
                    'name' => '[a-zA-Z][a-zA-Z0-9_-]*',
                    'id'     => '[0-9]+',
                ),
                'defaults' => array(
                    'controller' => 'Restaurantlist\Controller\Restaurantlist',
                    'action'        => 'view',
                ),
            ),
        ),
    ),
),

あなたの見解では:

echo $this->url('restaurantlist-view', array('id' => $list['id'], 'name' => $list['name']));
于 2013-05-28T06:41:33.497 に答える
0

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

ルートファイルで

//by placing other custom routes before (:any) will prevent to match any url 
$route['other/(:any)'] = 'mypage/other';
// Other routes as needed...
$route['(:any)'] = '/restaurantlist/view/$1';

HTML

<a href='<?php echo site_url($list['name']);?>'>Click</a>
于 2013-05-28T07:00:59.100 に答える