Issue
I am trying to add some extra fields in the Cakedc Users plugin default Users table 
But I can't figure it out how to do it, I didn't find anything in the documentation about this problem, I found a similar question here
But that person asked for a lot so he didn't get a lot of help, I also tried adding the extra field in the Mysql users table and in the register.ctp template  , But I find it's value is empty 
Solution
the question you mention is related to the previous version of the Plugin (for CakePHP 2).
You are doing right now, but the problem is the User Entity being too strict and blocking mass-assignment https://github.com/CakeDC/users/blob/3.1.5/src/Model/Entity/User.php#L30 (which is possibly a good thing to change in the Plugin itself to allow an even easier override). I'll add a ticket for this in a bit :)
In the current version it's very easy to extend the users table and add your own columns. For example, let's say you want to add a new column to your users table "phone".
- Add a new column in users table (usually involving a migration, you can "bake" this migration using
bin/cake bake migration AddPhoneToUsers phone:index
- Run the migration to apply the changes
bin/cake bake migration migrate
- Now follow instructions here https://github.com/CakeDC/users/blob/master/Docs/Documentation/Extending-the-Plugin.md#extending-the-model-tableentity to:
- Create empty Model and Entity classes extending the plugin classes
- Override $accessible property in your new Entity to something like - protected $_accessible = [ '*' => true, 'id' => false, 'role' => false, ]; 
- Lastly, add this override to your bootstrap.php file after loading the Plugin - Configure::write('Users.table', 'MyUsers'); 
The plugin will pick your customized Table and use the new fields coming from your custom register.ctp page.
We've created an improvement ticket here > https://github.com/CakeDC/users/issues/311 to relax $_accessible fields.
Thank you,
Answered By - steinkel Answer Checked By - Marie Seifert (PHPFixing Admin)
 
 Posts
Posts
 
 
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.