doctrine2 ve codeigniter2, üst sınıf için doğru bir yaklaşım çocuk özellikleri ile etkileşim

0 Cevap php

I'm searching for this for quite some time now. I saw few similar questions but not sure if they apply with doctrine2 and this problem. I'm trying to get started with CodeIgniter2 and Doctrine2, and I'm having some problems, I'm not OOP guru in php. I would like to have MainObject that will contains methods for CRUD and few others, and I want objects to extend that class and use parent's methods, but with child's properties. Since Doctrine2 uses Private Properties for objects, I cannot access these methods from parent class. For example:

   Class MainObject{
    public function validateFields(){
        //go over each field and validate/update if needed
    }
    public function store(){
        // do some validation, some logic, store, etc...
    }
   }
   Class User extends MainObject{
    /**
        * @Column(type="string", length=32, unique=true, nullable=false)
        */
        private $username;

        /**
         * @Column(type="string", length=64, nullable=true)
         */
        private $email;

   }

Şimdi, ben sadece aramak istiyorum

$user = new User();
//set properties, somehow
$user-__set($something);
//call validation or store or some method from the parent that will interact with child properties
$user->validate();
$user->store();
$user->uploadImage();
$user->formatPropertiesForSomethingSpecial();

I'm almost there to do this by using the ReflectionClass but I'm not sure that I'm doing this the right way? Or is there a way to have MainObject with all this methods, and then just pass User to it so it can do what it should do with user, is perhaps that the 'righter' approach? I don't think it will allow me to do something with Private properties from the user, but I guess that User can have its own getters and setters?

Ben yıllardır php yarı-OOP ile çalışıyorum, ama bu benim için yeni bir şey, bu yüzden herhangi bir tavsiye, öğretici, url, eleştiri, her şey için teşekkürler.

0 Cevap