how to extends (inheritance) model ?

Hi,

I am new with Yii Framework, I would like to know how to extends a model.

for example I have the following class:

class Employee (basic Model)

class Manager that extends Employee

class Supervisor extends Employee

class GeneralManager extends Manager

each class has additional fields like Manager has fieldArea

Supervisor has departementType

and GeneralManager has office

Can I have Employee, Manager, Supervisor and GeneralManager as 1 table so when I select all Employee, the Manager, Superviser and GeneralManager will be included.

how to write that in the Model in Yii ?

Hi adwin,

If your database table has all the fields you mentioned, you may want to use scenario to differentiate each employee type: for ‘supervisor’ scenario, you also mark ‘departmentType’ field as safe attribute, and so on.

is safe attribute same with nullable ?

Can I have some simple example for that ?

Presuming that the table is Employee, and the other types are simple subclasses, then I’d just create a model for Employee and create the other classes with the extends you note. This way you can create the specific classes, yet treat them polymorphically as Employees. You can place the source files in protected/components. I’d be inclined to create a employee interface too.