Hello everyone,
I am experiencing a strange issue with ActiveRecord. I am attempting to create a new record for a user, and each time it fails, although all of the POST data validates without any errors and Yii displays no errors, either.
I’ve ensured that all fields that are not allowed to be null by MySQL have data, and in fact, I can insert new records into the table in question via phpMyAdmin with no problem. I even created a method that prints out the SQL generated by ActiveRecord prior to the insert operation, and that SQL executes in phpMyAdmin without error (after I replace the bound parameters with legitimate values).
I’m sure I am missing something simple and obvious, but for the life of me, I cannot seem to find it.
Below is the code from my UserController’s method that is supposed to create the new record:
class UserController extends Controller
{
Other stuff ...
public function actionRegisterStudent()
{
$student = new User;
$student->setScenario('registerStudent');
// $this->performAjaxValidation($student, 'school-inquiry-form');
if (isset($_POST['User']))
{
$student->attributes = $_POST['User'];
$student->created = new CDbExpression('NOW()');
$attr = print_r($student->getAttributes(), TRUE);
Yii::trace("Student attributes after POST: {$attr}");
if($student->save())
{
Yii::app()->user->setFlash('success', "Congratulations! Your account has been created.");
// $this->redirect(Yii::app()->user->returnUrl);
}
else
{
Yii::trace("Could not save the user. SQL: {$student->getInsertCommand()}");
}
}
$this->render('studentRegForm', array('student'=>$student));
}
}
Any assistance would be much appreciated. TIA!