Validate Authentication question tp5

problem description

Call to undefined method appcommonvalidateKlassCourse::validate ()

related codes

Controller
namespace appindexcontroller;
use appcommonmodelCourse;
use appcommonmodelKlass;
use thinkRequest;
use appcommonvalidateKlassCourse;

public function save ()

{
    // 
    $Course = new Course();
    $Course->name = Request::instance()->post("name");

    // 
    if (!$Course->validate(true)->save()) {
        return $this->error(":" . $Course->getError());
    }

    // --------------------------  -------------------------- 
    // klass_id
    $klassIds = Request::instance()->post("klass_id/a");       // /a

    // klass_idklass_idcourse_id
    if (!is_null($klassIds)) {
        $datas = array();
        foreach ($klassIds as $klassId) {
            $data = array();
            $data["klass_id"] = $klassId;
            $data["course_id"] = $Course->id;     // CourseID
            array_push($datas, $data);
        }

        // saveAll()
        if (!empty($datas)) {
            $KlassCourse = new KlassCourse;
            **$result = $KlassCourse->validate(true)->saveAll($datas);**
            if (!$result) {
                return $this->error("-:" . $KlassCourse->getError());
            }
            unset($KlassCourse);    
        }
    }
    // -------------------------- (end) -------------------------- 
    
    unset($Course); 
    return $this->success("", url("index"));
}

validate the model
namespace appcommonvalidate;
use thinkValidate;

class KlassCourse extends Validate
{

protected $rule = [
    "klass_id"  => "require",
    "course_id" => "require"
];

}

Php
Jul.07,2021

visually you are using the ThinkPHP framework, and Validate is a separate validation class, not a model. The model is used for storage and the validation class is used for validation.
continue visual inspection, your model and validation class are renamed, the model does not have a validate method.

Menu