Set & Access Variables in error Page ZF2

后端 未结 1 1782
我在风中等你
我在风中等你 2021-01-16 14:15
class FrontController extends AbstractActionController {

    public function indexAction() {
        $this->layout()->setting_data = $this->getSetting()-&g         


        
相关标签:
1条回答
  • 2021-01-16 14:56

    Ok. As I understood from our conversation (see comments), your $setting_data variable not depends on any controller environment but only on some database data. In that case the first link from my first comment is what you need.

    public function onBootstrap($e)
    {
        $event = $e->getApplication()->getEventManager();
    
        $event->attach('render', function($e) {
            $serviceManager = $e->getApplication()->getServiceManager();
    
            $setting = $serviceManager->get('Front/Model/Setting');
            $setting_data = $setting->getSettingContent(1);
    
            $e->getViewModel()->setVariable('setting_data', $setting_data);
        });
    }
    
    0 讨论(0)
提交回复
热议问题