2012-04-18 23 views

回答

2

什麼樣的信息?我建議你使用filters

在你apps/frontend/config/filters.yml

rendering: ~ 
myfilter: 
    class: myCustomFilter 

創建文件lib/filter/myCustomFilter.php

<?php 
class myCustomFilter extends sfFilter 
{ 
    public function execute ($filterChain) 
    { 
    if ($this->isFirstCall()) 
    { 
     // do what ever you want here. 
     $config = Doctrine_Core::getTable('Config')->findAll(); 
     sfConfig::set('my_config', $config); 
    } 

    $filterChain->execute(); 
    } 
} 

然後,每一個地方,你可以檢索你的數據:

sfConfig::get('my_config'); 
3

如果過濾器解決方案不需要你的需求,你也可以用preEx創建一個基礎動作類ecute功能:

// app/frontend/lib/baseActions.class.php 

class baseActions extends sfActions 
{ 
    public function preExecute() 
    { 
     $this->myVar = .... // define your vars... 
    } 
} 

那麼你的模塊的操作類擴展您的baseActions類:

// app/frontend/modules/myModule/actions/actions.class.php 

class myModuleActions extends baseActions 
{ 
    public function executeIndex(sfWebRequest $request) 
    { 
     // var $this->myVar is available in any action and in your template 
     ... 
    } 
} 

,如果你要使用preExecute功能在你的模塊類的動作,記得打電話parent::preExecute()它。