Doubts on how to make inheritance with PHP using Framework CodeIgniter

1

I'm having doubts about using inheritance with PHP using the frame CodeIgniter.

  • I need to create an abstract class?
  • How do I search for a field that is in a certain class?
  • Ex: The Product Class has the fields:
     - name
     - preco_venda

    In the Categories class, you need to enter which category this product compose.   Attribute:
        - name

    Would anyone have any material that deals with this?

        
    asked by anonymous 19.05.2017 / 19:39

    1 answer

    1

    I believe that you have confused the concept of inheritance (which can be seen here ), with object relationships. As far as I understand, you have a Product class, in which you want to have the Name, Sales Price and Category information, and you also have another Category class that you have the Name information.

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

      

    Product Class with attributes product_id, category_id, name,   preco_venda.

         

    Class Category with the attributes id_category, name.

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

        
    08.06.2017 / 18:51