I’m new to CakePHP and i want to migrate from my custom lib to CakePHP.
I have, on my custom lib, for user attributes something like this:
auth_users table to know the “user_ids”:
CREATE TABLE IF NOT EXISTS `auth_users` (
`id` int(11) NOT NULL,
UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
auth_user_attributes table to store “user attributes”:
CREATE TABLE IF NOT EXISTS `auth_user_attributes` (
`user_id` int(11) NOT NULL,
`attribute` text NOT NULL,
`value` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
So whenever i want an user by user_id, my custom lib returns $system->auth->user->get(1) into:
Array(
'fullname' => 'José Moreira',
'username' => 'Cuss',
...
)
If i want to save user i have two methods, save an entire array $system->auth->user->save(user_id,user_attributes_array) or by attribute $system->auth->user->put(user_id, user_attribute, user_attribute_value)
How can i do something like this on CakePHP?
I would suggest you to redesign your schema to fit CakePHP conventions. Otherwise you will loose a lot of automagic and I see no sense for you to migrate to Cake if nobody forces you.
Usercannot have more than onefullnameorusername. There is no reason to putfullnameandusernameinto another table. Follow Simple Authentication and Authorization Application turorial and you will have no pain.Then you can save user attributes by calling User->UserAttribute->saveMany().