function register() { $user = new \website\model\User(); $user->login = $_POST['login']; $user->password = \website\utils\Password::hash($_POST['password']); $user->role = $_POST['role']; $user->first_name = $_POST['first_name']; $user->last_name = $_POST['last_name']; isset($_POST['date_of_birth']) and $user->date_of_birth = $_POST['date_of_birth']; //optional field return $user->save(); }
<?php require_once '../Common.php'; $common = \website\Common::getInstance(); $user = new \website\model\User(); $user->age = 15; $user->login = '******' . rand(); $user->password = \website\utils\Password::hash('5a1v564a1v564a1'); $user->first_name = 'toto'; $user->last_name = 'caca'; var_dump($user->save()); echo '------------------------<br/>'; var_dump($user); echo '------------------------<br/>'; $user->age = 16; var_dump($user->save()); echo '------------------------<br/>'; var_dump($user); echo '------------------------<br/>'; var_dump(\website\model\User::find()); echo '------------------------<br/>'; var_dump(\website\model\User::findOneWhere(['id'], [5])); var_dump(\website\model\User::findOneWhere(['id' => 5])); var_dump(\website\model\User::findOneWhere('id = ?', [5]));
private static function insertSampleData2() { $student = new \website\model\User(); $student->first_name = "franklin"; $student->last_name = "nameless"; $student->login = '******'; $student->password = '******'; $student->role = 'student'; $student->address = 'nowhere'; $student->date_of_birth = '2000-01-01'; $student->phone = '000'; $student->email = '*****@*****.**'; $student->valid = true; $student->save(); $student2 = new \website\model\User(); $student2->first_name = "franklin2"; $student2->last_name = "nameless"; $student2->login = '******'; $student2->password = '******'; $student2->role = 'student'; $student2->address = 'nowhere'; $student2->date_of_birth = '2000-01-01'; $student2->phone = '000'; $student2->email = '*****@*****.**'; $student2->valid = true; $student2->save(); $module1 = new \website\model\Module(); $module1->name = 'math'; $module1->code = 'math00'; $module1->coefficient = 2; $module1->valid = true; $module1->save(); $module2 = new \website\model\Module(); $module2->name = 'gym'; $module2->code = 'gym00'; $module2->coefficient = 1; $module2->valid = true; $module2->save(); $studentSub1 = new \website\model\StudentModuleSubscription(); $studentSub1->user_id = $student->getId(); $studentSub1->module_id = $module1->getId(); $studentSub1->mark = 18; $studentSub1->save(); $studentSub2 = new \website\model\StudentModuleSubscription(); $studentSub2->user_id = $student->getId(); $studentSub2->module_id = $module2->getId(); $studentSub2->mark = 2; $studentSub2->save(); $student2Sub1 = new \website\model\StudentModuleSubscription(); $student2Sub1->user_id = $student2->getId(); $student2Sub1->module_id = $module1->getId(); $student2Sub1->mark = 13; $student2Sub1->save(); $student2Sub2 = new \website\model\StudentModuleSubscription(); $student2Sub2->user_id = $student2->getId(); $student2Sub2->module_id = $module2->getId(); $student2Sub2->mark = null; $student2Sub2->save(); return ['student' => $student, 'student2' => $student2, 'module1' => $module1, 'module2' => $module2, 'studentSub1' => $studentSub1, 'studentSub2' => $studentSub2, 'student2Sub1' => $student2Sub1, '$student2Sub2' => $student2Sub2]; }