Reputation: 1
I use ObjectModel which allows me to persist data from a form in a database. My problem is quite simple, here is my function:
class AddFonction extends ObjectModel
{
public $id_customer;
public $fonction;
public $id_gender;
public $firstname;
public $lastname;
public $email;
public $passwd;
public $birthday;
public static $definition = [
'table' => 'basiccustomer',
'primary' => 'id_customer',
'multilang' => false,
'fields' => [
'id_customer' => ['type' => self::TYPE_INT, 'required' => false ],
'fonction' => ['type'=>self::TYPE_STRING, 'size'=> 255, 'required' => false],
'id_gender' => ['type' => self::TYPE_INT, 'required' => false],
'firstname' => ['type'=>self::TYPE_STRING, 'size'=> 255, 'required' => false],
'lastname' => ['type'=>self::TYPE_STRING, 'size'=> 255, 'required' => false],
'email' => ['type'=>self::TYPE_STRING, 'size'=> 255, 'required' => false],
'passwd' => ['type'=>self::TYPE_STRING, 'size'=> 255, 'required' => false],
'birthday' => ['type'=>self::TYPE_DATE, 'required' => false],
],
];
}
And I created my new table with this function :
public function installSql()
{
$sqlQuery = array();
$sqlQuery[] = 'CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'basiccustomer` (
`id_customer` INT(10) PRIMARY KEY NOT NULL,
`id_gender` INT(10),
`firstname` VARCHAR(255),
`lastname` VARCHAR(255),
`email` VARCHAR(255),
`passwd` VARCHAR(255),
`birthday` DATE,
`fonction` VARCHAR(255)
)';
$db = Db::getInstance();
foreach ($sqlQuery as $query) {
if (!$db->execute($query)) {
return false;
}
}
return true;
}
as you can see, the 3 problems concern my id_gender field because it's a checkbox and the result with this code gives me 0 each time, for the birthday, it gives me back the default value 0000-00-00, because it doesn't recognize the values and for the password, I see it in clear text, would you have an idea ?
Upvotes: 0
Views: 40
Reputation: 1491
Regarding id_gender
You can set a default value:
public $id_gender = 1
, for instance (you should probably think about having values in some constants)
The second problem. Date. Maybe you didn't populate the field correctly from your form?
And for the third issue, look at the Customer
class to see how it handles hashed passwords.
Upvotes: 1