Hi,
Let’s say I have main class named “Customer”, and “VIP”, “Loyal”, “Visitor” as sub-class of class Customer, the Customer class is the GUI to handle the sub-classes.
Then, how to extend it using Yii2 ?
Thanks,
Hi,
Let’s say I have main class named “Customer”, and “VIP”, “Loyal”, “Visitor” as sub-class of class Customer, the Customer class is the GUI to handle the sub-classes.
Then, how to extend it using Yii2 ?
Thanks,
What do you mean by
Lets assume you are talking about Models, but this apply in general to oop programming
Lets assume that a customer can be only one of the 3 "VIP", "Loyal", "Visitor"
A customer has common property to the 3 different status, like: name, address, telephone
VIP has vip only properties
Loyal has loyal only properties
Visitor has visitor only properties
You should do the contrary vip loyal and visitor extend the base class customer since customer is the "smallest container" with data that are common to the "bigger containers" vip loyal and visitor
class Customer extends \yii\db\ActiveRecord
{
}
class Vip extends Customer
{
}
class Loyal extends Customer
{
}
class Visitor extends Customer
{
}
What I mean that Customer is main class that the end user can access and via manage the customer types, and the other class will feed the Customer with the information.
Now, where to put the vip, loyal, and visitor class files in Yii2, and the name ?
Thanks
So again are we speaking about models? I think yes since you write:
if yes put them under models directory of your application
Are vip loyal and visitor tables?
if yes just define the relation and access the data…
http://www.yiiframework.com/doc-2.0/guide-db-active-record.html#relational-data
Which is better as relation customer has many of VIP loyal visitor, or they are blong to customer?
Yes, all have a table.
Depends on how do you manage data.
In theory it should be a relation 1 to 1.
Customer has either only 1 vip, loyal, visitor profile.
We are speaking about db design
Relationship is a type of cardinality that refers to the relationship between two entities.
Lets do some example:
1 to many
1 Customer can have many ordes
1 Custome can have many shipping address
1 to 1
Customer have 1 vip profile
many to many
many Ordes have many Products (different orders have in common the same product)
I think I will cancel the customer model, and create 3 models vip,customer,loyal because of privileges, that only manager can create/delete/update vip (for example).
Each user/employee will has his own right to manage the customer type, so what you think?
Thanks