1

私はこのURLを持っています:

http://mysite.com/pages/index?slug=how-does-it-work

そのURLを次のように変更したい:

http://mysite.com/how-does-it-work

ご覧のとおり、URL で削除されていますpageindexここのページはコントローラーであり、インデックスはコントローラーのアクションです。これは私のページコントローラーのコードです:

public function actionIndex($slug)
{
   if(!empty($slug))
   {
    $pagesInfo = Pages::model()->find(array("condition"=>"slug='$slug'"));
    $isAdmin = 0;
    if(isset(Yii::app()->user->idUser)){
       $isAdmin = Users::model()->findByPk(Yii::app()->user->idUser)->isAdmin;
    }

    if($pagesInfo !== null){
      $this->render('index',array(
        'pagesInfo'=>$pagesInfo,
        'isAdmin'=>$isAdmin,
       ));
    }else{
       throw new CHttpException(404,'Page cannot be found');
    }
   }
}

これも私の.htaccess

IndexIgnore */*
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

正直なところ、その URL を予想される URL 出力に変換する方法がわかりません。私がしたことを投稿しなかったのはそのためです。

あなたの助けは大歓迎です! ありがとう!:)

4

2 に答える 2

2

urlManager 設定を変更するだけです。たとえば、次のようになります。

'urlManager'=>array(
    'urlFormat'=>'path',
    'showScriptName'=>false,
    'rules'=>array(
        '<slug>'=>'page/index',

        // ... other rules
    ),
),

http://www.yiiframework.com/doc/guide/1.1/en/topics.url

于 2013-04-28T17:22:13.783 に答える
0

プロジェクトの config/main.php で「urlFormat」を「path」に変更しましたか?

このアクションをどのように呼び出しますか?

于 2013-04-28T15:40:32.997 に答える