0
votes

I'm looking at porting over some functions from the CakePHP 2.0 Users plugin into CakePHP 3.0. I've encountered this line in the old code:

$user = $this->{$this->modelClass}->passwordReset($this->request->data);

I debugged $user here and got a huge object filled with all kinds of data that I need. Perfect:

'properties' => [
    'password' => '*****',
    'id' => '53f7b636-e558-4eef-9064-1e78494ef653',
    'username' => 'blahblah',

 ...
 ]

I thought everything was working perfectly until the next line:

$Email->to($user[$this->modelClass]['email'])

This is the first line of an email about to send. Here, $user[$this->modelClass]['email'] returns null. So I tried accessing the object directly, like so:

debug($user['properties']['email'])

This still returns null, I'm assuming because I'm trying to access parameters from a model. I'm not exactly sure what is different in CakePHP 3.0 for $this->modelClass or if I goofed up elsewhere. Any ideas?

1
You are probably looking for $user->email. See also Cookbook > Entities > Accessing Entity Data - ndm
That's exactly it. I wonder why it was written the previous way in the CakeDC users plugin? (github.com/CakeDC/users) - cg22
Lookup what Controller::$modelClass does. If you extend the plugin and/or change the primary model the whole controller code will break if $modelClass is not used. Similar to why you should use $alias in models. Instead of ripping pieces out of the plugin I would appreciate if you fork and upgrade it instead. ;) Or help me finishing that one for 3.0 github.com/burzum/cakephp-user-tools - floriank
Awesome, thanks for the comment! Your 2.0 plugin is amazing and I've been using it for ages. It's a pleasure to have your comment here! The reason I was trying to understand the logic of it was because we're building a very lightweight one for our website, one that's very simple in comparison to yours. I'll link my buddy to the 3.0 and we'll see if we can contribute anything to yours! - cg22

1 Answers

0
votes

I should be $user->email, as the new ORM now returns objects instead of arrays