Doubts on how to do inheritance with PHP using Codeigniter Framework

Asked

Viewed 219 times

0

I’m having doubts to use inheritance with PHP using the frame Codeigniter.

  1. I need to create a class Abstract?
  2. How do I search for a field that is in a certain class?

Ex: The Product Class has the fields:
- name
- sale price

Already in the class Categories I need to insert which category this product composes.
Attribute:
- name

Would anyone have any material dealing with this subject?

  • 1

    You must have read the documentation, but right... https://www.codeigniter.com/docs

  • Yes I have consulted.

1 answer

0

I believe you confused the concept of inheritance (which can be seen here), relationship of objects. From what I understand, you have a Product class, in which you want to have the information of Name, Sale Price and Category and you also have another Category class that you have the information of Name.

Well, to know which category the product in question belongs to, you first have to normalize the classes thus:

Product class with the id_product, id_category, name, sale price.

Class Category with the id_category attributes, name.

This is how you make the relationship of objects correct. To make your data query work, you should read the concepts of primary and foreign key here .

Browser other questions tagged

You are not signed in. Login or sign up in order to post.