简体   繁体   English

如何在Cakephp 3中扩展Cakedc用户插件以使用自己的表

[英]How to extend Cakedc Users plugin to use own table in Cakephp 3

I want to extend users plugin so that i can remove username field and customize my table according to needs. 我想扩展用户插件,以便我可以删除用户名字段并根据需要自定义表格。 I have seen the github documentation for extending plugin but that doesn't help me much. 我已经看到了用于扩展插件的github文档,但这并没有太大帮助。 I tried to extend UserTable.php but it gives me error Unknown method "register". 我尝试扩展UserTable.php,但它给我错误未知方法“注册”。 Please suggest best way or simple code. 请提出最佳方法或简单代码。

Check this cloud9 environment created specifically to show how to extend the model and table as an example: https://ide.c9.io/steinkel/users-example-custom-table 检查专门创建的这个cloud9环境,以显示如何扩展模型和表格为例: https ://ide.c9.io/steinkel/users-example-custom-table

  • The example uses a custom table my_users 该示例使用自定义表my_users
  • The example uses a custom Table class MyUsersTable extending the CakeDC/Users.Users table 该示例使用自定义Table类MyUsersTable扩展CakeDC / Users.Users表
  • Keep in mind the field 'username' is used in SocialLogin and other features by default, if you are going to remove it ensure you configure the app to rely on another field. 请记住,默认情况下,SocialLogin和其他功能中使用了“用户名”字段,如果要删除它,请确保将应用程序配置为依赖其他字段。

Basically changes done to use a custom table are: 使用自定义表所做的更改基本上是:

  • Create a new database table, matching the original fields and add/remove fields based on your needs 创建一个新的数据库表,匹配原始字段并根据需要添加/删除字段
  • Create a new Table class in your app, extending the CakeDC/Users.Users table 在您的应用中创建一个新的Table类,扩展CakeDC / Users.Users表
  • Override required methods, like validation or finders in your table class 覆盖必需的方法,例如表类中的验证或查找器
  • Set your table in configuration key 'Users.table' like we did in 'config/users.php' 像在“ config / users.php”中一样在配置项“ Users.table”中设置表

     $config = [ 'Users' => [ //Table used to manage users 'table' => 'MyUsers', ] ]; return $config; 

And you are done :) 你完成了:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM