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 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看