Beste PRGers,
Momenteel ben ik bezig een webtool te schrijven, welke gebaseerd is op Doctrine2 (2.1.1) en CodeIgniter 2 (2.1.2) welke ik gecloned heb van https://github.com/wildly...Igniter-2-with-Doctrine-2
Nu heb ik een volgende entity gemaakt:
Middels wordt de entity op de volgende manier gevormd
Nu wil ik graag een wrapper model / class / functie schrijven welke een plaintext password omzet naar een hashed variant en zodoende kan valideren.
Ik dacht het volgende te kunnen doen.
Maar als ik vanuit de controller de setPassword functie wil aanroepen op het UserWrapper object krijg ik de volgende foutmelding
( ! ) Fatal error: Uncaught exception 'Doctrine\ORM\Mapping\MappingException' with message 'Class Entity\UserWrapper is not a valid entity or mapped super class.' in /home/matis/wwwroot/ci_checklists/application/libraries/Doctrine/ORM/Mapping/MappingException.php on line 147
( ! ) Doctrine\ORM\Mapping\MappingException: Class Entity\UserWrapper is not a valid entity or mapped super class. in /home/matis/wwwroot/ci_checklists/application/libraries/Doctrine/ORM/Mapping/MappingException.php on line 147
Hoe kan ik dit realiseren? Wat ik liever niet wil is de functie binnen de User class aanmaken, omdat deze telkens geupdated wordt gedurende de ontwikkeling.
Matis
Momenteel ben ik bezig een webtool te schrijven, welke gebaseerd is op Doctrine2 (2.1.1) en CodeIgniter 2 (2.1.2) welke ik gecloned heb van https://github.com/wildly...Igniter-2-with-Doctrine-2
Nu heb ik een volgende entity gemaakt:
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| namespace Entity; /* application/models/Entity/User.php */ /** * User Model * * @Entity * @Table(name="users") */ class User { /** * @Id * @Column(type="integer", nullable=false) * @GeneratedValue(strategy="AUTO") */ protected $id; /** * @Column(type="string", length=32, unique=true, nullable=false) */ protected $name; /** * @Column(type="string", length=128, nullable=false) */ protected $hashed_password; /** * @Column(type="string", length=255, unique=true, nullable=false) */ protected $email; |
Middels
./application/doctrine orm:generate-entities models
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
| <?php /* application/models/Entity/User.php */ namespace Entity; /** * User Model * * @Entity * @Table(name="users") */ class User { /** * @Id * @Column(type="integer", nullable=false) * @GeneratedValue(strategy="AUTO") */ protected $id; /** * @Column(type="string", length=32, unique=true, nullable=false) */ protected $name; /** * @Column(type="string", length=128, nullable=false) */ protected $hashed_password; /** * @Column(type="string", length=255, unique=true, nullable=false) */ protected $email; /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set name * * @param string $name * @return User */ public function setName($name) { $this->name = $name; return $this; } /** * Get name * * @return string */ public function getName() { return $this->name; } /** * Set hashed_password * * @param string $hashedPassword * @return User */ public function setHashedPassword($hashedPassword) { $this->hashed_password = $hashedPassword; return $this; } /** * Get hashed_password * * @return string */ public function getHashedPassword() { return $this->hashed_password; } /** * Set email * * @param string $email * @return User */ public function setEmail($email) { $this->email = $email; return $this; } /** * Get email * * @return string */ public function getEmail() { return $this->email; } } |
Nu wil ik graag een wrapper model / class / functie schrijven welke een plaintext password omzet naar een hashed variant en zodoende kan valideren.
Ik dacht het volgende te kunnen doen.
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| /* application/models/Entity/UserWrapper.php */ namespace Entity; class UserWrapper extends User { public function __construct() { parent::__construct(); } public function setPassword($plaintext) { $hashed_password = $this->hashPassword($plaintext); $this->setHashedPassword($hashed_password); } private function hashPassword($password) { $salt = bin2hex(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM)); $hash = hash('sha256', $salt . $password); return $salt . $hash; } } |
Maar als ik vanuit de controller de setPassword functie wil aanroepen op het UserWrapper object krijg ik de volgende foutmelding
( ! ) Fatal error: Uncaught exception 'Doctrine\ORM\Mapping\MappingException' with message 'Class Entity\UserWrapper is not a valid entity or mapped super class.' in /home/matis/wwwroot/ci_checklists/application/libraries/Doctrine/ORM/Mapping/MappingException.php on line 147
( ! ) Doctrine\ORM\Mapping\MappingException: Class Entity\UserWrapper is not a valid entity or mapped super class. in /home/matis/wwwroot/ci_checklists/application/libraries/Doctrine/ORM/Mapping/MappingException.php on line 147
Hoe kan ik dit realiseren? Wat ik liever niet wil is de functie binnen de User class aanmaken, omdat deze telkens geupdated wordt gedurende de ontwikkeling.
Matis
If money talks then I'm a mime
If time is money then I'm out of time