2012-04-18 2 views

답변

2

어떤 정보가 있습니까?

filters을 사용하는 것이 좋습니다. 에서

당신의 apps/frontend/config/filters.yml :

rendering: ~ 
myfilter: 
    class: myCustomFilter 

파일 lib/filter/myCustomFilter.php 만들기 :

sfConfig::get('my_config'); 
3

필터 솔루션 경우 :

<?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(); 
    } 
} 

그리고 모든 곳을, 당신은 당신의 데이터를 검색 할 수 있습니다 필요가없는 발을 가지고 있다면, 기본 동작 클래스를 만들 수도 있습니다. 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()를 호출해야합니다.

관련 문제