このURLを使用してYiiのURLにアクセスしたいwww.example.com/detail/post
。
detail
このURLを処理して、値を持つパラメーターを持つアクション、post
または名前付きパラメーターdetail
と値を持つアクションのいずれかを処理できるはずですpost
。
Yiiのドキュメントを読みましcreateUrl
たが、理解できませんでした。
このURLを使用してYiiのURLにアクセスしたいwww.example.com/detail/post
。
detail
このURLを処理して、値を持つパラメーターを持つアクション、post
または名前付きパラメーターdetail
と値を持つアクションのいずれかを処理できるはずですpost
。
Yiiのドキュメントを読みましcreateUrl
たが、理解できませんでした。
これがあなたが探しているものだと思います:
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に伝えています。
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のみを表示するようにします