problem description
Call to undefined method appcommonvalidateKlassCourse::validate ()
related codes
Controller
php
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
php
namespace appcommonvalidate;
use thinkValidate;
class KlassCourse extends Validate
{
protected $rule = [
"klass_id" => "require",
"course_id" => "require"
];
}