网址管理员在联系页面上显示404错误

时间:2013-12-16 17:16:57

标签: yii

我试图让我的网址看起来像mysite.com/contact,但很遗憾,它在联系页面上显示404错误。登录页面工作。该文件位于protected/view/site/contact.php

'urlManager'=>array(
                'urlFormat'=>'path',
                //'urlSuffix'=>'.html',
                'rules'=>array(
                    '<view:(about|terms|faq|privacy)>' => 'site/page',
                    '<action:(contact|login)>' => 'site/<action>',
                    '<action:(registration|create)>' => 'user/<action>',
                    '<controller:\w+>/<id:\d+>'=>'<controller>/view',
                    '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
                    '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
                ),
                'showScriptName' => false,
            ),

3 个答案:

答案 0 :(得分:1)

确保在SiteController.php中有此功能

/**
 * Displays the contact page
 */
public function actionContact()
{
    $model=new ContactForm;
    if(isset($_POST['ContactForm']))
    {
        $model->attributes=$_POST['ContactForm'];
        if($model->validate())
        {
            $name='=?UTF-8?B?'.base64_encode($model->name).'?=';
            $subject='=?UTF-8?B?'.base64_encode($model->subject).'?=';
            $headers="From: $name <{$model->email}>\r\n".
                "Reply-To: {$model->email}\r\n".
                "MIME-Version: 1.0\r\n".
                "Content-Type: text/plain; charset=UTF-8";

            mail(Yii::app()->params['adminEmail'],$subject,$model->body,$headers);
            Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
            $this->refresh();
        }
    }
    $this->render('contact',array('model'=>$model));
}

答案 1 :(得分:0)

我这样渲染我的

'contact' => array('site/contact'),

答案 2 :(得分:0)

    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

使用上面的代码

在项目文件夹中创建.htaccess