Reuse overlay overlay and entities

I ran into a conceptual problem today; I am developing an education related web application where users will train themselves with multiple question selection forms.

This is a project that can be repetitive, because it will probably lead to some other projects around the same idea, but a little gained.

To be more efficient next time, I would like to make a reusable binding for MQC forms; I have my architecture right in my head that does not depend on any other object in the application besides the User. This is not a problem because it is just part of the relationship and I think I can pass it as a parameter.

The biggest problem here is that: I have generic relay types "content types" created in this particular application and contain some important information that all other entities in the application should provide. The problem is that my base class in a reusable package also needs to inherit from this generic class.

And what is where I'm amazed: how do I define something in common, but in this particular case inherits it from one of my application objects? Is this possible, or is it a real bad concept? Maybe I should use an intermediate class and add a relationship to all my other objects, but then I wouldn't be able to select many different content types together (for example, for story purposes) ...

thanks in advance


source to share

1 answer

If I understand your idea correctly, I advise you the following solution: I will post the code from my some reusable "CustomerReviewBundle" bundle, so I think you can easily adapt it for your case:

  • Create an interface in a reusable kit ProductInterface

    interface ProductInterface

  • Then you can create an object in your reusable bundle with a reference to ContentTypeInterface

    use Doctrine\ORM\Mapping as ORM;
    use Symfony\Component\Validator\Constraints as Assert;
    use \Gamma\CustomerReview\CustomerReviewBundle\Interfaces\ProductInterface;
     * @ORM\Entity(repositoryClass="Gamma\CustomerReview\CustomerReviewBundle\Repository\CustomerReviewRepository")
     * @ORM\Table(name="customer_review", indexes={
     * @ORM\Index(name="enabled_idx", columns={"enabled"}),
     * @ORM\Index(name="rating_idx", columns={"enabled", "rating"}),
     * @ORM\Index(name="sort_idx", columns={"date"})
     * })
    class CustomerReview
    other properties
         * Product
         * @ORM\ManyToOne(targetEntity="Gamma\CustomerReview\CustomerReviewBundle\Interfaces\ProductInterface")
        private $product; 

  • Then I connect my reusable package to it in my application

And can determine which product type can be used for reviews by following the setting in config.yml

    # ...
        # ...
             Gamma\CustomerReview\CustomerReviewBundle\Interfaces\ProductInterface: \MyApp\ProductBundle\Entity\Product


So you can do the same, just change the Product to your class ContentType

and then you can define specific content types for each of your application that uses your reusable package

More information



All Articles