Monday, January 2, 2012

symfony sfDoctrineGuardPlugin module wise permission

if you want to moudle wise permission to user in symfony

its work in symfony 1.4 and sfDoctrineGuardPlugin 5.0

add permission (permssion name is credential name)

and group (group name is module name)

now create one filterfile (filterfile add in /apps/appname(frontend|backend)/lib) folder

<?php

class groupcheckFilter extends sfFilter
{
public function execute($filterChain)
{
// Filters don't have direct access to the request and user objects.
// You will need to use the context object to get them
$context = $this->getContext();
$request = $context->getRequest();
$user = $context->getUser();
//$user->getAllPermissionNames();
$user_group = $user->getGroupNames();
echo $module = $context->getModuleName();
//secure file in default folder so bellow if condition and redirect path
if (!in_array($module,$user_group) && $module != 'default')
{
return $context->getController()->redirect('/default/secure/');
}else {
// Execute next filter
$filterChain->execute();
}
}
}

?>

file save with groupcheckfilter.class.php

in app.yml file add bellow line after security: or # insert your own filters here

groupcheck:
class: groupcheckFilter

how to see xml preview in browser php

xml preview view in browser $xml = new DOMDocument('1.0', 'UTF-8');                 $xml->preserveWhiteSpace = false; ...