src/Listener/RelatedModelsListener.php
public function publishRelatedModels($action = null, $entity = null)
    {
        $models = $this->models($action);

        if (empty($models)) {
            return;
        }

        $controller = $this->_controller();

        foreach ($models as $name => $association) {
            list(, $associationName) = pluginSplit($association->getName());
            $viewVar = Inflector::variable($associationName);
            if (array_key_exists($viewVar, $controller->viewVars)) {
                continue;
            }

            $finder = $this->finder($association);
            $query = $association->find()->find($finder, $this->_findOptions($association));
            $subject = $this->_subject(compact('name', 'viewVar', 'query', 'association', 'entity'));
            $event = $this->_trigger('relatedModel', $subject);

            $controller->set($event->getSubject()->viewVar, $event->getSubject()->query->toArray());
        }
    }
public function publishRelatedModels($action = null, $entity = null)
    {
        $models = $this->models($action);

        if (empty($models)) {
            return;
        }

        $controller = $this->_controller();

        foreach ($models as $name => $association) {
            list(, $associationName) = pluginSplit($association->getName());
            $viewVar = Inflector::variable($associationName);
            if (array_key_exists($viewVar, $controller->viewVars)) {
                continue;
            }

            $finder = $this->finder($association);
            $query = $association->find()->find($finder, $this->_findOptions($association));
            $subject = $this->_subject(compact('name', 'viewVar', 'query', 'association', 'entity'));
            $event = $this->_trigger('relatedModel', $subject);

            $controller->set($event->getSubject()->viewVar, $event->getSubject()->query->toArray());
        }
    }
public function publishRelatedModels ( $ action = null , $ entity = null ) { $ models = $ this -> models ( $ action ) ; if ( empty ( $ models ) ) { return ; } $ controller = $ this -> _controller ( ) ; foreach ( $ models as $ name => $ association ) { list ( , $ associationName ) = pluginSplit ( $ association -> getName ( ) ) ; $ viewVar = Inflector :: variable ( $ associationName ) ; if ( array_key_exists ( $ viewVar , $ controller -> viewVars ) ) { continue ; } $ finder = $ this -> finder ( $ association ) ; $ query = $ association -> find ( ) -> find ( $ finder , $ this -> _findOptions ( $ association ) ) ; $ subject = $ this -> _subject ( compact ( 'name' , 'viewVar' , 'query' , 'association' , 'entity' ) ) ; $ event = $ this -> _trigger ( 'relatedModel' , $ subject ) ; $ controller -> set ( $ event -> getSubject ( ) -> viewVar , $ event -> getSubject ( ) -> query -> toArray ( ) ) ; } }
Find and publish all related models to the view
for an action

@param null|string $action If NULL the current action will be used
@param null|\Cake\ORM\Entity $entity The optional entity for which we we trying to find related
@return void
Find and publish all related models to the view for an action