如何修复此错误 404 系统找不到请求的操作“索引”


how to fixed this Error 404 The system is unable to find the requested action "index"

当我调用控制器时显示错误 404 系统找不到请求的操作"索引"。

其测试控制器文件

class TestController extends Controller
{
   public function actionLogin()
{
    $model=new SignupForm();
    if(isset($_POST['SignupForm']))
   {
       // collects user input data
        $model->attributes=$_POST['SignupForm'];
        // validates user input and redirect to previous page if validated
        if($model->validate())
           $this->redirect(Yii::app()->user->returnUrl);
   }
    // displays the login form
    $this->render('index',array('model'=>$model));
}
  }

其模型文件

class SignupForm extends CFormModel
  {
    public $username;
    public $password;
    public $rememberMe=false;
    public function rules()
    {
        return array(
            array('username, password', 'required'),
            array('rememberMe', 'boolean'),
            array('password', 'authenticate'),
        );
    }
    public function authenticate($attribute,$params)
    {
        $this->_identity=new UserIdentity($this->username,$this->password);
        if(!$this->_identity->authenticate())
            $this->addError('password','Incorrect username or password.');
    }
  }

当我调用控制器时显示错误404系统找不到请求的操作"索引",那么如何修复此错误

动作 "index" 是 Yii 控制器中的默认动作。您可以更改此行为,设置特定控制器的默认索引。

class TestController extends Controller
{
    public $defaultAction = 'login';
    public function actionLogin()
    {
    }
}

在这种情况下,当你运行/index.php?r=test 时,就像/index.php?r=test/login。

控制器中没有 actionIndex(( 方法。因此,要么调用 www.yourwebsite.com/index.php?r=test/login,要么在测试控制器中创建 actionIndex(( 方法。