File tree Expand file tree Collapse file tree 3 files changed +16
-3
lines changed Expand file tree Collapse file tree 3 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -22,19 +22,20 @@ class RegistrationController extends AbstractActionController
22
22
public function indexAction ()
23
23
{
24
24
// A test instantiation to make sure it works. Not used in the application. You can remove the next line
25
- $ myValidator = new ConfirmPassword ();
25
+ // $myValidator = new ConfirmPassword();
26
26
$ form = new RegistrationForm ();
27
27
$ form ->get ('submit ' )->setValue ('Register ' );
28
28
29
29
$ request = $ this ->getRequest ();
30
30
if ($ request ->isPost ()) {
31
31
$ form ->setInputFilter (new RegistrationFilter ($ this ->getServiceLocator ()));
32
32
$ form ->setData ($ request ->getPost ());
33
- if ($ form ->isValid ()) {
33
+ if ($ form ->isValid ()) {
34
34
$ data = $ form ->getData ();
35
35
$ data = $ this ->prepareData ($ data );
36
36
$ auth = new Auth ();
37
37
$ auth ->exchangeArray ($ data );
38
+
38
39
/*
39
40
// this is replaced by
40
41
// 1) Manualy composing (wiring) the objects
@@ -52,7 +53,8 @@ public function indexAction()
52
53
echo '<pre>';
53
54
var_dump($user7);
54
55
echo '</pre>';
55
- */
56
+ */
57
+
56
58
// OR
57
59
// 2) Using the service Locator
58
60
$ this ->getUsersTable ()->saveUser ($ auth );
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ class Auth implements InputFilterAwareInterface
23
23
public $ usr_registration_token ;
24
24
public $ usr_email_confirmed ;
25
25
26
+ // Hydration
26
27
// ArrayObject, or at least implement exchangeArray. For Zend\Db\ResultSet\ResultSet to work
27
28
public function exchangeArray ($ data )
28
29
{
@@ -41,6 +42,14 @@ public function exchangeArray($data)
41
42
$ this ->usr_registration_token = (!empty ($ data ['usr_registration_token ' ])) ? $ data ['usr_registration_token ' ] : null ;
42
43
$ this ->usr_email_confirmed = (isset ($ data ['usr_email_confirmed ' ])) ? $ data ['usr_email_confirmed ' ] : null ;
43
44
}
45
+
46
+ // Extraction. The Registration from the tutorial works even without it.
47
+ // The standard Hydrator of the Form expects getArrayCopy to be able to bind
48
+ public function getArrayCopy ()
49
+ {
50
+ return get_object_vars ($ this );
51
+ }
52
+
44
53
45
54
protected $ inputFilter ;
46
55
Original file line number Diff line number Diff line change @@ -80,6 +80,8 @@ public function saveUser(Auth $auth)
80
80
'usr_registration_token ' => $ auth ->usr_registration_token ,
81
81
'usr_email_confirmed ' => $ auth ->usr_email_confirmed ,
82
82
);
83
+ // If there is a method getArrayCopy() defined in Auth you can simply call it.
84
+ // $data = $auth->getArrayCopy();
83
85
84
86
$ usr_id = (int )$ auth ->usr_id ;
85
87
if ($ usr_id == 0 ) {
You can’t perform that action at this time.
0 commit comments