ChrisBull ChrisBull - 16 days ago 5
MySQL Question

Account verification in CakePHP

I am using CakePHP 3.x. I have created the code that creates a new user in the following table;

users

id | email | password | verification | verified | last_activity | date_created


The verified column will be a foreign key to the 'user_verification' table.


  1. Should by convention, this be named verification_id and could you confirm the names of the table etc?



The relationship is that Users hasOne verification. When the user is created another entry in the user_verification table will be created which will populate the user entry with its id.


  1. Does this seem like a logical way to get about creating a verification table? I do want them to be in separate tables.

  2. Can someone point me in the direction for accessing the verification table while inside the Users controller.



Thanks!

Answer

Yes, with CakePHP it's best to name a column verification_id if it is related to another table. This way, when you bake the model it automatically does the work for you.

You can access the verification table inside the Users controller by loading the model.

$this->loadModel('Verification');

Controller (Loading Additional Models)

EDIT: According to CakePHP's documentation, you should give your table a plural name such as verifications not verification.

Comments