简体   繁体   中英

TYPO3 : How to determine child-objecttypes of specific parent domain-model?

I have some different domain-models, each being parent of different sub-models. All of those domain-models extend themselves out of a basic model class and I want to write a general function in the base-model, that deals with subclasses of the current model. Therefore, I need to find a way, to dynamically get all child-model-classes of a given domain-model. Can this be done somehow ? Perhaps via Object-Storage-Definitions or similar ?!

Update : as mentioned in the comment section, mny question had nothing to do with TYPO3, it was a general php-question .. solution for my question are reflection-classes.

我想您的问题与TYPO3无关,因此请在此处查看这个一般的PHP问题线程和可能的解决方案。

You are talking about Database Relationships. Yes, this can be done in TYPO3.

Each model should be mapped to a table . So, let's take for example the Category domain model and parent property

class Category extends AbstractEntity
{
    /**
     * @var \TYPO3\CMS\Extbase\Domain\Model\Category
     */
    protected $parent = null;

    /**
     * @return \TYPO3\CMS\Extbase\Domain\Model\Category 
     */
    public function getParent()
    {
      if ($this->parent instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) {
          $this->parent->_loadRealInstance();
      }
      return $this->parent;
  }

  /**
   * @param \TYPO3\CMS\Extbase\Domain\Model\Category $parent
   */
  public function setParent(\TYPO3\CMS\Extbase\Domain\Model\Category $parent)
  {
      $this->parent = $parent;
  }

The parent property will return the parent category. The same logic is when you want to get the childs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM