I suggest your learn about databases first. :)
But to try and help you on the way - assume that the table Users table represents the physical people that will be accessing your site, thus the Users table identifies these people.
Each of the Users may play a role in your site, either as a Teacher or as a Student ... or even both. So for CakePHP to know about which roles, Teacher and/or Student the User is playing, there must be a way to identify the relationship between them.
So in each of the tables, Teachers and Students, there need to be a reference to the specific User in the Users table. Thus you add the user_id column in the Teachers and Students tables.
In the CakePHP models, the setup should then be as follows:
User hasOne Teacher
User hasOne Student
Teacher belongsTo User
Student belongsTo User
Hope the above helps you on the way. :)
Enjoy, John
On Saturday, 31 May 2014 08:49:42 UTC+3, ajt wrote:
-- But to try and help you on the way - assume that the table Users table represents the physical people that will be accessing your site, thus the Users table identifies these people.
Each of the Users may play a role in your site, either as a Teacher or as a Student ... or even both. So for CakePHP to know about which roles, Teacher and/or Student the User is playing, there must be a way to identify the relationship between them.
So in each of the tables, Teachers and Students, there need to be a reference to the specific User in the Users table. Thus you add the user_id column in the Teachers and Students tables.
In the CakePHP models, the setup should then be as follows:
User hasOne Teacher
User hasOne Student
Teacher belongsTo User
Student belongsTo User
Hope the above helps you on the way. :)
Enjoy, John
On Saturday, 31 May 2014 08:49:42 UTC+3, ajt wrote:
Hi,
I am confused about how the User table is linked to other tables.
To keep things simple I have a working version of a linked cakephp/mysql that can display ,add,edit records.
I add in security with a admin role who can see every page.
Everything is OK but I will need to add users with access to only somethings.
I have these tables
teachers
student
teacher-student (tutor sessions)
User
The question how do I link the User to the students,techers table as the user table seems to be a special case?
Would I need a user_id in these 2 tables and the user has foreign keys of teacher_id and student_id?
What about admin roles who can see all pages as they dont need a teacher or student id?
Or dont I bother linking tables as User table is a special case?
Do I need to set up a teachers table with id and also a user_id which is the same thing?
In cakephp I link like this for example.
class User extends AppModel {
public $hasOne = array('Teacher','Student');
class Teacher extends AppModel
{
public $hasOne = 'User';
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment