When defining rules, does the field name have to match the column name in the database?
I'm having a problem where if the field name and the column name don't match, the rules are displayed and nothing is saved to the database.
What works:
Database
user_id | username
Field
<?php echo Form::input('username', $username, array('id' => 'username')); ?><?php echo Arr::get($errors, 'username');?>
Model
class Model_User extends ORM {
protected $_primary_key = 'user_id';
public function rules()
{
return array(
'username' => array(
array('not_empty'),
),
);
}
}
Messages
return array(
'username' => array(
'not_empty' => 'You must provide a username.',
),
);
What doesn't work:
Database
user_id | username
Field
<?php echo Form::input('membername', $username, array('id' => 'username')); ?><?php echo Arr::get($errors, 'membername');?>
Model
class Model_User extends ORM {
protected $_primary_key = 'user_id';
public function rules()
{
return array(
'membername' => array(
array('not_empty'),
),
);
}
}
Messages
return array(
'membername' => array(
'not_empty' => 'You must provide a username.',
),
);
It seems if I change the field name to something other than username the rules function doesn't work correctly.
If I don't apply any rules, changing username to something else doesn't cause any problems with saving data to the database.