我引用此解决方案https://stackoverflow.com/a/15167450/2910183,并发生错误:
编译错误:声明 AppBundle \ Block \ NewsletterBlockService :: execute()必须兼容 同 索纳塔\ BlockBundle \块\ BlockServiceInterface ::执行(奏鸣曲\ BlockBundle \块\ BlockContextInterface $ blockContext,Symfony \ Component \ HttpFoundation \ Response $ response = NULL)
代码
我的app/config/config.yml
sonata_block:
default_contexts: [cms]
blocks:
# enable the SonataAdminBundle block
sonata.admin.block.admin_list:
contexts: [admin]
sonata.user.block.menu: ~ # used to display the menu in profile pages
sonata.user.block.account: ~ # used to display menu option (login option)
sonata.block.service.text: ~
sonata.block.service.rss: ~
sonata.block.service.newsletter: ~
sonata_admin:
dashboard:
blocks:
-
position: left
type: sonata.admin.block.admin_list
settings:
groups: [default, app.admin.group.content]
-
position: right
type: sonata.admin.block.admin_list
settings:
groups: [default]
- { position: left, type: sonata.block.service.newsletter}
我的一部分 /private/var/www/learning_sonata/app/config/services.yml
sonata.block.service.newsletter:
class: AppBundle\Block\NewsletterBlockService
arguments: [ "sonata.block.service.newsletter", @templating ]
tags:
- { name: sonata.block }
我的 /private/var/www/learning_sonata/src/AppBundle/Block/NewsletterBlockService.php
namespace AppBundle\Block;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Block\BlockContext;
use Sonata\BlockBundle\Block\BlockServiceInterface;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\CoreBundle\Validator\ErrorElement;
use Sonata\BlockBundle\Block\BaseBlockService;
//use Sonata\BlockBundle\Block;
class NewsletterBlockService extends BaseBlockService
{
public function getName()
{
return 'My Newsletter';
}
public function getDefaultSettings()
{
return array();
}
public function validateBlock(ErrorElement $errorElement, BlockInterface $block)
{
}
public function buildEditForm(FormMapper $formMapper, BlockInterface $block)
{
}
public function execute(BlockInterface $block, Response $response = null)
{
// merge settings
$settings = array_merge($this->getDefaultSettings(), $block->getSettings());
return $this->renderResponse('InstitutoStoricoNewsletterBundle:Block:block_my_newsletter.html.twig', array(
'block' => $block,
'settings' => $settings
), $response);
}
}
谢谢devilcius!
我参考你的答案,清除上面的错误,但是出现了新的错误:
方法" id" for object" Sonata \ BlockBundle \ Block \ BlockContext"不 SonataBlockBundle中不存在:Block:第11行的block_base.html.twig
文件路径 vendor/sonata-project/block-bundle/Resources/views/Block/block_base.html.twig
<div id="cms-block-{{ block.id }}" class="cms-block cms-block-element">
{% block block %}EMPTY CONTENT{% endblock %}
</div>
奏鸣曲版
sonata-project/admin-bundle 3.1.0 The missing Symfony Admin ...
sonata-project/block-bundle 3.0.0 Symfony SonataBlockBundle
sonata-project/cache 1.0.7 Cache library
sonata-project/core-bundle 3.0.0 Symfony SonataCoreBundle
sonata-project/doctrine-orm-admin-bundle 3.0.1 Symfony Sonata / Integrate...
sonata-project/exporter 1.4.1 Lightweight Exporter library
我读了这个resource,它说这是版本专业版。
你们可以提出一些想法,伙计们?
答案 0 :(得分:0)
扩展BaseBlockService时,您没有实现方法签名。
use Sonata\BlockBundle\Block\BlockContextInterface;
public function execute(BlockContextInterface $blockContext, Response $response = null)
{
return $this->renderResponse('InstitutoStoricoNewsletterBundle:Block:block_my_newsletter.html.twig', array(
'block' => $blockContext->getBlock(),
'settings' => $blockContext->getSettings()
), $response);
}