我正在学习本教程:
https://sonata-project.org/bundles/block/master/doc/reference/your_first_block.html
我能够保存一个新块,但是当我尝试使用SELECT * FROM (
SELECT ROW_NUMBER() OVER(PARTITION BY receipt.IdUser ORDER BY receipt.IdUser ASC) AS RowId, user.IdUser, receipt.value
FROM user INNER JOIN receipt ON user.IdUser = receipt.IdUser
)
as s
PIVOT
(
max(value)
FOR RowId IN ([1], [2], <max number of the receipts> )
)AS pvt
按钮删除块时,我的日志会显示以下错误:
request.CRITICAL:未捕获的PHP异常 Symfony的\分量\ OptionsResolver \异常\ UndefinedOptionsException: “选项”标题“,”网址“不存在。定义的选项是:”“。”在 /usr/src/app/vendor/symfony/symfony/src/Symfony/Component/OptionsResolver/OptionsResolver.php 第685行
我需要在哪里定义字段才能解决此问题?如果遵守相关教程,该定义会是什么样的?
====
编辑1:这是我的区块服务的内容:
remove
...这里是admin.yml的相关内容:
<?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\AdminBundle\Form\FormMapper;
use Sonata\CoreBundle\Validator\ErrorElement;
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
use Sonata\BlockBundle\Block\Service\AbstractAdminBlockService;
class PatrickBlockService extends AbstractAdminBlockService
{
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'url' => false,
'title' => 'Insert the rss title',
'template' => '@SonataBlock/Block/block_core_rss.html.twig',
));
}
public function buildEditForm(FormMapper $formMapper, BlockInterface $block)
{
$formMapper
->add('settings', 'sonata_type_immutable_array', array(
'keys' => array(
array('url', 'url', array('required' => false)),
array('title', 'text', array('required' => false)),
)
))
;
}
public function validateBlock(ErrorElement $errorElement, BlockInterface $block)
{
$errorElement
->with('settings.url')
->assertNotNull(array())
->assertNotBlank()
->end()
->with('settings.title')
->assertNotNull(array())
->assertNotBlank()
->assertMaxLength(array('limit' => 50))
->end()
;
}
public function execute(BlockContextInterface $blockContext, Response $response = null)
{
// merge settings
$settings = $blockContext->getSettings();
$feeds = false;
if ($settings['url']) {
$options = array(
'http' => array(
'user_agent' => 'Sonata/RSS Reader',
'timeout' => 2,
)
);
// retrieve contents with a specific stream context to avoid php errors
$content = @file_get_contents($settings['url'], false, stream_context_create($options));
if ($content) {
// generate a simple xml element
try {
$feeds = new \SimpleXMLElement($content);
$feeds = $feeds->channel->item;
} catch (\Exception $e) {
// silently fail error
}
}
}
return $this->renderResponse($blockContext->getTemplate(), array(
'feeds' => $feeds,
'block' => $blockContext->getBlock(),
'settings' => $settings
), $response);
}
}
到目前为止,我已尝试删除configureOptions()方法中涉及的两个字段,这似乎没有什么区别。
====
编辑2:
当我说“我要保存一个新块”时,我的意思是信息会保存在数据库中,以供日后检索。但是,我在该步骤中看到了同样的错误。
答案 0 :(得分:0)
对于今后几年用Google搜索的人:我最终放弃了教程并向相反的方向发展,基本上是在分析Sonata提供的现有逻辑。这是我记忆所做的模糊版本:
将vendor/sonata-project/block-bundle/Block/Service/RssBlockService.php
的文件克隆到src/AppBundle/Block/RssBlockService.php
相应地更新了admin.yml
和sonata_block.yml
。
启用tail -f var/logs/dev.log
并调整我的use
语句以修补任何剩余的粗糙点。
创建了一个新的Twig模板并调整了我的代码以使用该模板。
答案 1 :(得分:0)
在这种情况下,错误消息令人困惑。
这不是您需要在此处设置的默认选项,而是默认设置,但是由于这两个选项和设置都使用OptionsResolver类,因此反馈的措辞令人困惑。
package service;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import dao.EmployeeDao;
@Service
public class TestBean {
@Autowired(required=true)
private EmployeeDao dao;
public void m1() {
int i=dao.updateEmp(77, 89);
System.out.println(i);
}
public void m2() {
Map m=dao.findEmpById(12);
System.out.println(m);
}
public void m3() {
List l=dao.findAllEmps();
Iterator itr=l.iterator();
while(itr.hasNext()) {
Map m=(Map) itr.next();
System.out.println(m);
}
}
}