所以我有一个已配置路由的控制器我的动作如下所示
/**
* List of brands
*
* @return array
*/
public function listAction()
{
$brandIds = \Drupal::entityQuery('node')
->condition('type', 'brand')
->sort('title', 'asc')
->execute();
return [
'addition_arguments' => [
'#theme' => 'page--brands',
'#brands' => is_array($brandIds) ? Node::loadMultiple($brandIds) : [],
'#brands_filter' => \Drupal::config('field.storage.node.field_brand_categories')->get()
]
];
}
Run Code Online (Sandbox Code Playgroud)
我想在我的树枝模板主题文件页面中使用#brands和#brands_filter - 品牌,但我从未看到它经历过.
有人可以帮忙吗?
谢谢
UPDATE
解决了这个问题
在您的模块my_module.module文件中添加以下内容
function module_theme($existing, $type, $theme, $path)
{
return [
'module.brands' => [
'template' => 'module/brands',
'variables' => ['brands' => []],
],
];
}
Run Code Online (Sandbox Code Playgroud)
在您的控制器中使用
return [
'#theme' => 'mymodule.bands', …Run Code Online (Sandbox Code Playgroud) 我有点陷入困境,无法找到答案.
在我的应用测试中,我创建了两个实体用户和注释都正确映射.
我已经创建了一个小控制器,根据用户将注释和数据添加到ACL表,如果我创建我的注释作为标准用户与"ROLE_USER"关联,并尝试以用户身份访问它角色'ROLE_ADMIN'我被拒绝访问,似乎完全忽略了security.yml层次结构.
我知道这可以通过添加而不是用户ID ROLE_USER等来工作,但我不想这样做.
我的代码示例如下.
CommentController
<?php
namespace ACL\TestBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use ACL\TestBundle\Forms\Type\commentType;
use ACL\TestBundle\Entity\Comment;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Acl\Domain\ObjectIdentity;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Acl\Permission\MaskBuilder;
class DefaultController extends Controller
{
/**
* @Route("/", name="_default")
* @Template()
*/
public function indexAction()
{
die('success');
}
/**
* @Route("/comment/new/")
* @Template()
*/
public function newAction(Request $request)
{
$comment = new Comment();
$form = $this->createForm(new commentType(), $comment);
$form->handleRequest($request);
if ($form->isValid()) {
$comment->setUsers($this->getUser());
$em = $this->getDoctrine()->getManager();
$em->persist($comment);
$em->flush(); …Run Code Online (Sandbox Code Playgroud)