【问题标题】:how to fixed this Error 404 The system is unable to find the requested action "index"如何修复此错误 404 系统无法找到请求的操作“索引”
【发布时间】:2013-10-13 07:09:25
【问题描述】:

当我调用控制器时显示错误 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 系统无法找到请求的操作“索引”所以如何修复此错误

【问题讨论】:

  • 调用test/login 而不是test/ 调用默认操作index
  • 或者在你的控制器中定义默认操作public $defaultAction = 'test';。也可以在init()中定义。

标签: php yii


【解决方案1】:

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

class TestController extends Controller
{
    public $defaultAction = 'login';

    public function actionLogin()
    {
    }
}

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

【讨论】:

    【解决方案2】:

    您的控制器中没有 actionIndex() 方法。所以要么调用 www.yourwebsite.com/index.php?r=test/login 要么在你的测试控制器中创建一个 actionIndex() 方法。

    【讨论】:

      猜你喜欢
      • 2013-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-21
      • 2022-01-05
      相关资源
      最近更新 更多