0

これが私の設定です:

config.php

 'urlManager'=>array(
          'urlFormat'=>'path',
          'rules'=>array(
           '<controller:\w+>/<id:\d+>'=>'<controller>/view',
           '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
           '<controller:\w+>/<action:\w+>'=>'<controller>/<action>'
          ),
          'showScriptName'=>false,
 ),

.htaccess

Options +FollowSymlinks
#+FollowSymLinks must be enabled for any rules to work, this is a security
#requirement of the rewrite engine. Normally it's enabled in the root and we
#shouldn't have to add it, but it doesn't hurt to do so.

RewriteEngine on
#Apache scans all incoming URL requests, checks for matches in our
#.htaccess file 
#and rewrites those matching URLs to whatever we specify.

#allow blank referrers.
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?site.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?site.dev [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?dev.site.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d


# otherwise forward it to index.php
RewriteRule . index.php

レイアウトメニューで私はこれを持っています:

$this->widget('zii.widgets.CMenu', 
    array('items'=>
        array(
            array(
                'label'=>Yii::t('site','A'),
                'url'=>array('/site/index')
            ),
            array(
                'label'=>Yii::t('site','Q'),
                'url'=>array('rooms/index')
            ),
            array(
                'label'=>Yii::t('site','G'),
                'url'=>array('gastronomy/index')
            ),
            array(
                'label'=>Yii::t('site','A'),
                'url'=>array('activity/index')
            ),
            array(
                'label'=>Yii::t('site','S'),
                'url'=>array('services/index')
            ),
            array(
                'label'=>Yii::t('site','C'),
                'url'=>array('contacts/index')
            ),
            array(
                'label'=>Yii::t('site','R'),
                'url'=>array('booking/index')
            )
        )
    )
);

ここでは、インデックスを明示的に呼び出す必要があるようです。明示的に呼び出す必要があるようです。

この設定では、取得したリンクをクリックするたびに、たとえば次のようになります。

http://site.dev/rooms/index

私が取得したい間:

http://site.dev/rooms/

インデックス名なし。

ここで何が欠けていますか?

4

1 に答える 1

3

インデックスエントリファイルとデフォルトのアクションには違いがあります。あなたはそれらのものを台無しにしています。表示すると、リンクがインデックスエントリファイルの場所の'showScriptName'=>trueようなものに変更されることがわかります。/index.php/rooms/indexindex.php

オプションでわかるように、リンクに'showScriptName'=>falseはそれがありません。これはindex.php、リンクからエントリスクリプトを正常に削除したことを意味します。

これで、あなたroom/indexcontroller/actionURLルートの一部になりました。roomはコントローラーであり、indexアクションです。http://site.dev/rooms/代わりに表示するには、次のhttp://site.dev/rooms/indexようにURLルートを編集する必要があります。

'urlManager'=>array(
    'urlFormat'=>'path',
    'rules'=>array(
        '<controller:\w+>/<id:\d+>'=>'<controller>/view',
        '<controller:\w+>'=>'<controller>/index',
        '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
        '<controller:\w+>/<action:\w+>'=>'<controller>/<action>'
    ),
    'showScriptName'=>false,
),

'<controller:\w+>'=>'<controller>/index'追加した行に注意してください。これにより、の代わりにルートindexを作成するデフォルトのアクションが作成されます。controllercontroller/index

于 2012-09-03T15:24:37.430 に答える