3

I am new to yii2 and I have created a form, however it is showing the following error while loading the page:

Unknown Method – yii\base\UnknownMethodException

Calling unknown method: yii\web\Request::post()

The code in studController

public function actionStudform()
    {
        $data = Stud::find()->asArray()->all();   

        $model = new Stud;
        if(($model->load(Yii::$app->request->post())) && $model->validate())
        {            
              echo "validate";
        }           
        else
        {
            return $this->render('studform',['model'=>$model,'data'=>$data]);
        }
    }
1
  • show your controller with all code Commented Sep 16, 2016 at 13:40

2 Answers 2

1

ok

i also faced that problem and i had sorted out also

in yii2 you have to check that if form is posted or not ? if form posted then you have to fetch data or print data

try my code it working in my case with same error

public function actionStudform()
    {
        $data = Stud::find()->asArray()->all();   

        $model = new Stud;
        $request = Yii::$app->request;
        if($request->isPost)
        {
            if(($model->load($request->post)) && $model->validate())
            {                    
                print_r($request->post['Stud']);
            }
            return $this->render('studform',['model'=>$model,'data'=>$data]);
        }
        else
        {
            return $this->render('studform',['model'=>$model,'data'=>$data]);
        }
    }
Sign up to request clarification or add additional context in comments.

Comments

0

Check namespace use Yii in your controller

OR

I think this is again the composer dependency resolver doing unexpected things:

  • you require yiisoft/yii2 in your composer.json but do not have the composer asset plugin installed.
  • then the dependency resolver does not find packages with vendor bower-asset so it looks for other versions of yiisoft/yii2 that do not have conflict
  • The result is to install the beta version of yii2 to be installed

The correct solution as already mentioned is to install the composer-asset-plugin:

php composer.phar global require "fxp/composer-asset-plugin:1.0.*@dev"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.