Search code examples
cakephpcakedc

How to add extra fields in CakeDc Users plugin


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

    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,