我使用KnpSnappyBundle 1.6.0和wkhtmltopdf 0.12.5从 PHP 中的 HTML 生成 PDF,如下所示:
$html = $this->renderView(
'pdf/template.html.twig',
[ 'entity' => $entity, ]
);
return new PdfResponse($snappy->getOutputFromHtml($html,
['encoding' => 'UTF-8', 'images' => true]), 'file'.$entity->getUniqueNumber().'.pdf'
);
Run Code Online (Sandbox Code Playgroud)
我的问题:在我的生产服务器上,当我引用与我的代码托管在同一台服务器上的资产(图像或 css)时,生成 PDF 大约需要 40-50 秒。即使我只使用托管在同一台服务器上的小图像也需要 40 秒。我可以使用托管在另一台服务器上的更大的图像,并且会立即生成 PDF。
我的服务器在提供资产或文件方面的速度并不慢。如果我只是将 HTML 呈现为一个页面,它会立即发生(有或没有资产)。当我在本地(在我的笔记本电脑上)从我的生产服务器请求资产以生成 PDF 时,它也会立即发生。
我在 HTML 中需要的需要呈现为 PDF 的资产都具有绝对 URL,这是 wkhtmltopdf 工作所必需的。例如:<img src="https://www.example.com/images/logo.png">困难的是,一切正常,只是非常缓慢。没有指出会导致超时的不存在的资产。
我一开始以为可能与 wkhtmltopdf 有关,所以我尝试了不同的版本和不同的设置,但这并没有改变任何东西。我还尝试指向同一台服务器上的另一个域,问题仍然存在。我尝试不使用 KnpSnappyBundle,但问题仍然存在。
所以我现在猜测是服务器问题(或与 wkhtmltopdf 的组合)。我正在运行Nginx-1.16.1并通过 SSL 提供所有内容。我安装了OpenSSL 1.1.1d 2019 年 9 月 10 日(库:OpenSSL 1.1.1g 2020 …
在 CKEditor5 中,我正在创建一个插件来插入一个span元素来显示工具提示。这个想法是显示一个带有(脚)注释的工具提示,而元素本身将显示一个增量数字。在 CKEditor4 我做了这样的事情:
CKEDITOR.dialog.add( 'footnoteDialog', function( editor ) {
return {
title: 'Footnote Properties',
minWidth: 400,
minHeight: 100,
contents: [
{
id: 'tab-basic',
label: 'Basic Settings',
elements: [
{
type: 'text',
id: 'content',
label: 'Content of footnote',
validate: CKEDITOR.dialog.validate.notEmpty( "Footnote field cannot be empty." )
}
]
}
],
onOk: function() {
var dialog = this;
var footnote = editor.document.createElement( 'span' );
footnote.setAttribute('class', 'footnote');
footnote.setAttribute('data-toggle', 'tooltip');
footnote.setAttribute( 'title', dialog.getValueOf( 'tab-basic', 'content' ) );
footnote.setText('[FN]');
editor.insertElement( footnote …Run Code Online (Sandbox Code Playgroud) 我正在寻找仅 CSS 的解决方案(如果可能的话)。所以我的 HTML 没有改变,也没有使用 JavaScript。这是我的 HTML:
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perspiciatis vitae commodi sunt voluptate ut ratione fugit iusto sequi. Voluptatibus provident, quo at vel vero praesentium ratione eligendi. Ab iure sequi quis est odio nihil a fugit labore, vero omnis cum.
</p>
<img src="http://www.fillmurray.com/284/196">
Run Code Online (Sandbox Code Playgroud)
我的 HTML 是大量标签的一部分,这些<p>标签还包含应看起来像常规段落的常规 。
我唯一能想到的就是使用inline-block和的组合float:
p {
display: inline-block;
max-width: calc(100% - 284px);
}
img {
display: inline-block; …Run Code Online (Sandbox Code Playgroud) 我正在设置一个新服务器并安装了Ubuntu 18.04和Apache2。我的项目存储在/var/www/project. 在apache2.conf我添加
<Directory /var/www/project/>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
Run Code Online (Sandbox Code Playgroud)
在我的虚拟主机文件中,我指向/var/www/project/public
当我转到服务器的 IP 地址时,我看到了我的项目并且一切正常,除了一件事:
每当我使用php bin/console cache:clear我的目录权限清除缓存时,都会var搞砸,这会导致生产环境中出现错误。
我可以解决这个问题:
chmod -R 777 var/
Run Code Online (Sandbox Code Playgroud)
但是即使我再次清除缓存,问题也会再次出现。我尝试了不同的用户,包括root,但总是同样的问题。我不明白是什么原因造成的。在文件权限的文档中,它说:
在 Symfony 中
3.x,你需要做一些额外的工作来确保你的缓存目录是可写的。但这不再是事实!在 Symfony 中4,一切都会自动运行
那么不适合我,但是什么可能导致问题?
我试图在不使用框架的情况下学习JS。对以下内容略有疑问:
<div class="js-button"></div>
Run Code Online (Sandbox Code Playgroud)
在jQuery中,我可以使用以下命令创建一个提交按钮:
$("<button type='submit'>Save</button>").appendTo($(".js-button"));
Run Code Online (Sandbox Code Playgroud)
在普通的JS中,我可以这样做:
document.querySelector(".js-button").innerHTML += "<button type='submit'>Save</button>";
Run Code Online (Sandbox Code Playgroud)
这是完全一样的,对吧?还有其他方法吗?如果您碰巧在写作上=犯了错误,而+=不是您会碰到我要避免的大问题。
在 git 存储库中每个文件类型添加和删除了多少行代码?最好能够请求这些过去X提交的统计信息。所以说我会为过去的100 提交请求这个,我的预期结果将是这样的:
.css, 100 files changed, 2879 insertions(+), 1134 deletions(-)
.js, 17 files changed, 415 insertions(+), 502 deletions(-)
.php, 6 files changed, 478 insertions(+), 176 deletions(-)
.py, 10 files changed, 156 insertions(+), 56 deletions(-)
Run Code Online (Sandbox Code Playgroud)
这一定是可能的,但我找不到解决方案。我已经阅读了这个问题,并尝试使用Gitstats和RepoExplorer。
组件Cell的状态alive可以是true或false。
如果alive为真,则Cell呈现为div带有类的a alive(想想康威的生命游戏)。状态alive每秒更新一次:
function Cell(props) {
const [alive, setAlive] = useState(
Math.random() < props.aliveProbability / 100
);
useEffect(() => {
const interval = setInterval(
() => setAlive(Math.random() < props.aliveProbability / 100),
1000
);
return () => clearInterval(interval);
}, []);
return (
<div className={"cell " + (alive ? "alive" : "")}>{props.children}</div>
);
}
Run Code Online (Sandbox Code Playgroud)
对于单个单元来说,这工作得很好。但是,当向网格添加多个单元组件时,渲染速度会减慢,并且是按顺序而不是同时进行。细胞越多,速度就越慢。如何解决这个问题?
我正在使用一个不是特别为symfony(TNTsearch)制作的包,并且已经将我想要使用的所有函数放在我调用的服务中TNTsearchHelper.php.此服务需要一些变量,包括可以在.env文件中找到的变量.我目前在我的班级中定义和构建这些:
class TntSearchHelper
{
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
$config = [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'databasename',
'username' => 'user',
'password' => 'pw',
'storage' => 'my/path/to/file',
'charset' => 'utf8',
'collation' => 'utf8_general_ci',
];
$this->config = $config;
}
Run Code Online (Sandbox Code Playgroud)
我真正想要的是简单地使用.env文件中设置的数据库变量.有没有办法做到这一点?此服务未注册,services.yaml因为这不是autowire: true选项所必需的,所以我没有任何配置选项/文件用于我的服务,config并想知道我是否可以保持这种方式.
我有两个输入字段,fee和currency.已经工作:currency如果用户进入0该字段,我的字段将被禁用fee.我想是有外地currency禁用也当字段fee为空(这有时是默认值,但不总是).我的代码到目前为止:
$("#fee").on('input', function() {
var activeFee = (this.value === '0' || this.value === null ) ? true : false;
$('#currency').prop('disabled', activeFee);
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Fee: <input id="fee"><br>
Currency: <input id="currency"><br>Run Code Online (Sandbox Code Playgroud)
或者:JSFiddle
代码中没有按预期工作的部分是:
(this.value === '0' || this.value === null )
Run Code Online (Sandbox Code Playgroud)
如何确保currency在两种情况下都禁用该字段是fee"0"还是空(空)?
According to the doctrine documentary:
The prePersist event occurs for a given entity before the respective EntityManager persist operation for that entity is executed. It should be noted that this event is only triggered on initial persist of an entity (i.e. it does not trigger on future updates).
The last part is important and makes me wonder; is there a difference in that case with the __contruct() method?
Let's say I want to set the creation date and time …
在 symfony 中,我有一个 entity Program,它具有属性image。上传图像、命名它们并将它们放在正确的目录中是使用VichUploaderBundle. 该实体如下所示:
//...
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Assert\Image(
* maxSize="5M",
* mimeTypesMessage="The file you tried to upload is not a recognized image file"
* )
* @Vich\UploadableField(mapping="program_image", fileNameProperty="imageName")
*
* @var File
*/
private $image;
/**
* @ORM\Column(type="string", length=191, nullable=true)
*/
private $imageName;
//...
Run Code Online (Sandbox Code Playgroud)
现在我希望在上传图像之前对图像进行处理,我已经用一些返回 base64 字符串的 JS 完成了这项工作。我把这个字符串放在一个隐藏的输入字段中,base64Image. 然后我在我的控制器中检索这个字符串并尝试将它变成一个图像,我可以像这样保存到我的实体中:
if ($form->isSubmitted() && $form->isValid()) { …Run Code Online (Sandbox Code Playgroud) 在古腾堡编辑器中,我尝试向编辑器中的所有(包括核心)块添加内联样式。使用editor.BlockEdit,可以对编辑器中的所有块进行更改。例如,如果我想将它们全部包装起来并向包装器添加一些内联样式(在红色的情况下),我可以这样做:
const withColorControl = createHigherOrderComponent((BlockEdit) => {
return (props) => {
return (
<div style={{color: 'red'}}>
<BlockEdit {...props}/>
</div>
);
};
}, 'withColorControl');
addFilter('editor.BlockEdit', 'example/with-color-control', withColorControl);
Run Code Online (Sandbox Code Playgroud)
我的问题是,这会创建一个额外的div,这是我不想要的。我想要的是实际块接收内联样式,如下所示:
<Fragment>
<BlockEdit {...props} style={{color: 'red'}}/>
</Fragment>
Run Code Online (Sandbox Code Playgroud)
这不起作用,因此我的问题:如何在编辑器中将内联样式添加到古腾堡块而不包装块?
PS 保存内联样式或诸如此类的东西不是问题,这仅与编辑器有关。
PS2 另外editor.BlockListBlock不起作用。虽然这可以用来向元素添加类,但我无法添加内联样式。