dtol41388 2018-02-08 05:14
浏览 108

Yii2框架:调用未定义的函数app \ controllers \ VisitorForm

I am working in Yii2 Framework. In my model, I have class

class VisitorForm extends Model
{
    public $station;
    public $center;

    public function rules()
    {
        return [
            [['station', 'center'], 'required'],
            ];
    }
}

and in my SiteController class I have the action method

 public function actionVisitor()
    {

        $model = VisitorForm();
        if($model->load(yii::$app->request->get())){
            return $this->render('visitor', ['model' => $model]);
        }
    }

Also, I have included use app\models\VisitorForm;. Also in my view directory I have visitor.php.

The above code is exactly similar to the EntryForm code give in Yii2 Definitive Guide.

But I am getting the error while executing the code at line

$model = VistorForm(); // throwing error at this line


Call to undefined function app\controllers\VisitorForm()

I am not able to figure out, what is going wrong with me. at the line, where I create the model

  • 写回答

2条回答 默认 最新

  • dongpu2694 2018-02-08 05:21
    关注

    You have add this line on SiteController.php Cause you are going to use VistorForm class inside the SiteController

    use app\models\VisitorForm;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog