1

このURLを使用してYiiのURLにアクセスしたいwww.example.com/detail/post

detailこのURLを処理して、値を持つパラメーターを持つアクション、postまたは名前付きパラメーターdetailと値を持つアクションのいずれかを処理できるはずですpost

Yiiのドキュメントを読みましcreateUrlたが、理解できませんでした。

4

2 に答える 2

2

これがあなたが探しているものだと思います:

main.phpを次のように更新します(コントローラー/詳細を示す部分のコントローラーをコントローラーの名前に変更します)

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

つまり、基本的には、detail / number形式のリクエストはすべてコントローラーに送信され、アクション「detail」を使用してから「post」という変数を渡すことをYiiに伝えています。

于 2012-04-16T13:26:46.100 に答える
0

mod rewriteを有効にしていて、htaccessファイルに以下を配置したい場合

php_value upload_max_filesize 1M
DirectoryIndex index.php

Options +FollowSymlinks
RewriteEngine on

# 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

config/main.phpファイルの「urlManager」配列に以下を追加します。

'showScriptName'=>false,

URLからindex.phpを削除し、domain.com / controller/actionの形式のURLのみを表示するようにします

于 2012-05-13T20:44:35.983 に答える