2011-09-04 73 views
0
if (!$this->getUser()->isAuthenticated()) 
{ 
    $this->redirect('login/index'); 
} 

我想为不同模块中的许多操作添加此代码。我必须为每个操作复制此代码?我想做些什么:symfony中的重构代码

//module 

class Invite 
public function executeIndex { 
sfConfig:get('redirect'); 
} 


class Home 
public function executeIndex { 
sfConfig:get('redirect'); 
} 

public function executeShow { 
    sfConfig:get('redirect'); 
} 

如果不能在不同的模块,虽然它可能在一个单一的?

回答

1

您可以使用symfony的内置安全过滤器。

如果你要保护的整个模块,使用以下内容创建应用程序/应用程序/模块/模块/配置/ security.yml:

all: 
    is_secure: true 

如果你只是想显示的动作是安全的:

show: 
    is_secure: true 

请注意,您只需要操作的名称,不包括结果(例如成功)。

你可以只用内建安全层做很多事情,甚至更多的是像sf(Doctrine)GuardPlugin。有关更多信息,请参阅Gentle introduction to symfony, chapter 6, action security