PHP Symfony 1.4 - the best way to transfer data from an action to a component?

I create a breading menu in my symfony application: I create a list of links in execute {Action}, then I use the component in layout.php to display it, so I'm looking for a way to transfer data from the action to this component. I can use sfContext as a registry, but maybe there is a better way?

+4
source share
2 answers

Usually you should use the slot like this in the action view:

slot('breadcrumb', $links);

And then in your layout.php:

 <?php if(has_slot('breadcrumb')): ?> <?php include_component('modulename', 'breadcrumb', get_slot('breadcrumb')); ?> <?php endif; ?> 

Essentially, slot uses a special namespace in the context (or perhaps its answer ... some sfParameterHolder instance somewhere, hehe) as a registry of slot names / values, so the solution you were thinking about is already implemented :-)

+3
source

In your action:

 $this->links = array('link1', 'link2', 'linkn'); 

In your template:

 <?php include_component('modulename', 'breadcrumb', array('links' => $links); ?> 
+2
source

Source: https://habr.com/ru/post/1399004/


All Articles