Relational Databases

Ok, So I am new to MVC, and still getting the hang of OOP programming. (I come from a good old fashioned Turbo C++ background)

I am trying to use 3 tables:

Table 1: Store User data (id, name, email, etc.)

Table 2: Store Roles (Admin, user, sudo etc.)

Table 3: Store which user has which access rights. (similar to a lookup table, but not quite ;)

I know there are other ways of doing this, but once I have this down, I can use it with other things like invoice and quote and class lists all referencing and pointing to each others tables and info etc.

I have gone through the forums, I have gone through the blog demo and yii definitive guide, but alas, I am really struggling with the correct way of doing things!

My main problem at the moment is simply getting the data from 3 different tables at the same time while in either the views of User or in the background operations of things.

Any awesome advice??

Sounds to me like 2 things going on here.

  1. You are trying to ‘roll your own’ permission scheme here. I would strongly suggest you read up on RBAC and accessControl filter in the Guide.

  2. You need to review the model relations in the Guide and define the relations for the model of each table you mention. Once you do that you can access the related data easily.

Thanks for the reply!

1.) I will be converting to a much stronger version of access control later, I’m just trying to get the functionality up and running correctly for many_to_many relations so that I can use it in other parts of my program. Currently using user and role so that everybody can understand what I’m trying to achieve.

2.) I’ve tried various model relations, but nowhere does it show me a nice example of how to directly access the table data from different tables in 1 model.

i.e. I’d like to access User->user_id (this is from the User table and should be equal to the current logged in persons user_id (this i can currently do very easily)). BUT, then in the same model access User->role (this variable is the role name of the current users role (not the role_id… the actual name that is associated with the role)

Ok, let me try make the above clearer:

I can easily access the user tables data, as I’m in the User model. But, then I’d like to create a variable that looks up the role_id that is associated with the current user. This data is found in the UserRole table. THEN, it must go to the Role table and fetch the corresponding name (role_name) for that role_id. hence I can have a single string that can be used across the application for the current logged in user. (obviously once I have this sorted, I’ll have a method in accessing data from related tables in different models)

I’m sure this must be a standard thing to do in most applications? Is this not the correct way to store data and handle data? It’s similar to the post_comment table in blog demo. Just I cannot find how to create this variable, nor how to access this variable, or data when needed.

try here http://www.yiiframew…cal-rbac-scheme

and there http://www.yiiframew…with-a-php-file

also http://www.yiiframew…related-models/

hope will be satisfied.

bipu