使用 Forms(Working with Forms) 代码疑似有误,更正后正常 [ 求助交流 ]
含错误代码的教程:
错误代码:
<?php
namespace app\controllers;
use Yii;
use yii\web\Controller;
use app\models\EntryForm;
class SiteController extends Controller
{
    // ...现存的代码...
    public function actionEntry()
    {
        $model = new EntryForm;
        if ($model->load(Yii::$app->request->post()) && $model->validate()) {
            // 验证 $model 收到的数据
            // 做些有意义的事 ...
            return $this->render('entry-confirm', ['model' => $model]);
        } else {
            // 无论是初始化显示还是数据验证错误
            return $this->render('entry', ['model' => $model]);
        }
    }
}
中的$model = new EntryForm; 是否正确?如果正确,将会报错validate() 是未知方法。
本人仅凭一些粗浅的Java知识认为:
正确代码应改成如下:
...
$model = new EntryForm();
...
共 2 条回复
zmxaple
            注册时间:2017-04-24
最后登录:2017-06-24
在线时长:0小时27分
    最后登录:2017-06-24
在线时长:0小时27分
- 粉丝0
- 金钱15
- 威望0
- 积分15

