我在Symfony 3中使用了SonataAdminBundle.因为我使用Symfony 3,我仍然无法使用SonataUserBundle.所以我只使用带有FOSUserBundle的SonataAdminBundle.
现在我试图实现的是隐藏每个角色的特定路线.例如,我只有三个角色;
超级管理员拥有管理员拥有的所有角色,管理员拥有所有第三个角色,第三个显然拥有ROLE_USER.超级管理员应该能够创建新用户并为他分配角色.超级管理员还应该能够更改用户的密码.用户应该能够更改自己帐户的密码.最后,超级管理员不应该更改自己的角色和创建新用户的其他角色.
如何在不使用SonataUserBundle的情况下实现此目的.为了删除路线部分我试过这样的事情:
protected function configureRoutes(RouteCollection $collection)
{
$securityContext = $this->getConfigurationPool()->getContainer()->get('security.authorization_checker');
if (!$securityContext->isGranted('ROLE_SUPER_ADMIN')) {
$collection->remove('create');
$collection->remove('edit');
}
}
Run Code Online (Sandbox Code Playgroud)
但我想有更好的解决方案.我完全了解有关安全性的官方文档,但我对此感到困惑,这是否意味着我必须对我security.yml文件中所有不同管理员的每个角色进行硬编码?没有SonataUserBundle,这甚至可以工作吗?我不想为ACL添加额外的数据库表.
有人可以帮助和/或提供一个很好的例子吗?我会非常感激的.
我创建了一个脚本,用于从CSV文件中读取数据,检查数据中是否已存在数据,如果不存在则导入数据.如果数据确实存在(特定产品的代码),则需要从CSV文件更新其余信息.
例如; 我的代码为WTW-2LT,在我的CSV文件中名为Alex和姓Johnson.该脚本检查代码为WTW-2LT且名为Alex和姓氏Johnson的成员是否已存在,如果有,则需要从脚本更新联系人详细信息和额外详细信息(还需要检查主题和讲师等其他详细信息,所有细节都在CSV中的一行中,如果它不存在,则只需要创建新成员.
我的脚本到目前为止我用最少的其他检查来防止分心现在;
while ($row = fgetcsv($fp, null, ";")) {
if ($header === null) {
$header = $row;
continue;
}
$record = array_combine($header, $row);
$member = $this->em->getRepository(Member::class)->findOneBy([
'code' =>$record['member_code'],
'name' =>$record['name'],
'surname' =>$record['surname'],
]);
if (!$member) {
$member = new Member();
$member->setCode($record['member_code']);
$member->setName($record['name']);
$member->setName($record['surname']);
}
$member->setContactNumber($record['phone']);
$member->setAddress($record['address']);
$member->setEmail($record['email']);
$subject = $this->em->getRepository(Subject::class)->findOneBy([
'subject_code' => $record['subj_code']
]);
if (!$subject) {
$subject = new Subject();
$subject->setCode($record['subj_code']);
}
$subject->setTitle($record['subj_title']);
$subject->setDescription($record['subj_desc']);
$subject->setLocation($record['subj_loc']);
$lecturer = $this->em->getRepository(Lecturer::class)->findOneBy([
'subject' => $subject,
'name' => $record['lec_name'],
'code' => $record['lec_code'], …Run Code Online (Sandbox Code Playgroud) 我有一个与这个问题相同的场景的问题,除了它可能发生_在文本中不止一个.
一个例子;
57b42a0557cdd_Filename_whatever.pdf
Run Code Online (Sandbox Code Playgroud)
我怎么能省略所有内容,直到第一个下划线(包括下划线)来保持其余部分 Filename_whatever.pdf
随机单引号可以具有不同的长度,但它与实际文件名之间始终存在下划线.
就像上面提到的问题一样; {{ filename|split('_')[1] }}可能会工作,但如果实际的文件名有下划线怎么办?
我希望它最好只用于显示目的,因为完整的唯一名称也用于项目的不同部分.
print_r在我的阵列上做一个时,我得到以下输出;
Array
(
[0] => Array
(
[id] => 178
[name] => Briar Price
)
[1] => Array
(
[id] => 90
[name] => Bradley Kramer
)
[2] => Array
(
[id] => 508
[name] => Calvin Yang
)
[3] => Array
(
[id] => 457
[name] => Charles Valenzuela
)
... and so on
Run Code Online (Sandbox Code Playgroud)
如何修改数组看起来像这样;
Array
(
[178] => Briar Price
[90] => Bradley Kramer
[508] => Calvin Yang
[457] => Charles Valenzuela
... and so on
) …Run Code Online (Sandbox Code Playgroud)