U95895 U95895 - 2 months ago 17
PHP Question

Unknown Method – yii\base\UnknownMethodException Calling unknown method: yii\web\Request::post()

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]);
}
}

Answer

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]);
        }
    }
Comments