我对内容安全策略有疑问。每当我尝试将 JavaScript 包含到我的项目中时,都会收到内容安全策略错误。
<!DOCTYPE html>
<html>
<head>
<title>Symfony</title>
<script src="{{ asset('myscript.js') }}"></script>
</head>
<body>
// ...
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我已经尝试过:
Header set Content-Security-Policy "script-src 'self';"<meta http-equiv="Content-Security-Policy" content="script-src 'self'">是否有机会使用 EasyAdmin 实现的字段禁用用户的字段?
我想向用户显示“isPaid”的布尔值,但我不想让他改变它,只给他看(支付网关这样做)
谢谢你的帮助!
我实际上正在开发一个需要使用 Symfony 4.4 和 EasyAdmin 3 的 WYSIWYG 界面的项目。
我尝试按照此文档https://symfony.com/doc/2.x/bundles/EasyAdminBundle/integration/ivoryckeditorbundle.html以及我在 Google 或 Youtube 上找到的其他一些教程来安装 FOS_CKEditor ,但不幸的是我不明白为什么 CKEditorField 没有显示在我的管理仪表板上。我想我已经错过了一些东西。
一些帮助将不胜感激,这是我的配置文件:
Fos_ckeditor:
#config/packages/fos_ckeditor.yaml
twig:
form_themes:
- '@FOSCKEditor/Form/ckeditor_widget.html.twig'
fos_ck_editor:
configs:
basic_conf:
toolbar: full
Run Code Online (Sandbox Code Playgroud)
易管理员:
#config/packages/easy_admin.yaml
easy_admin:
design:
form_theme:
- "@EasyAdmin/form/bootstrap_4.html.twig"
- "@FOSCKEditor/Form/ckeditor_widget.html.twig"
Run Code Online (Sandbox Code Playgroud)
我还尝试通过添加以下内容来定义 CrudController 中的 FieldType:
#CrudController
public function configureFields(string $pageName): iterable
{
return [
..//
TextareaField::new('corps', 'Corps')
->setFormType(CKEditorType::class),
Run Code Online (Sandbox Code Playgroud)
但它没有奏效。
预先感谢您的帮助!
我有一个带有图像的实体,我正在使用 EasyAdmin 3.0 和 VichUploader 1.14 在管理控制台中上传图像。我的问题是我无法在管理控制台中显示图像。我怎样才能做到这一点 ?这是我的实体:
class Question
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
* @Groups({"question"})
*/
private $id;
/**
* @ORM\Column(type="text", nullable=true)
* @Groups({"question"})
*/
private $title;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="stand_image", fileNameProperty="imageName", size="imageSize")
*
* @var File|null
*/
private $imageFile;
/**
* @ORM\Column(type="string", nullable=true)
*
* @var string|null
*/
private $imageName;
/**
* @ORM\Column(type="integer", nullable=true)
*
* @var int|null
*/ …Run Code Online (Sandbox Code Playgroud) 当我使用时:
public function configureFields(string $pageName): iterable
{
return [
AssociationField::new('XYZ')
];
}`
Run Code Online (Sandbox Code Playgroud)
我收到错误"Object of class App\Entity\XYZ could not be converted to string"
当我添加->autocomplete()到 时AssociationField::new('XYZ'),它可以工作,但在保存时显示错误"Expected argument of type "?string", "App\Entity\XYZ" given at property path "XYZ".
使用该字段进行多对一关系的正确方法是什么?Symfony Easy Admin 文档https://symfony.com/doc/current/EasyAdminBundle/fields/AssociationField.html根本没有帮助。
我创建了一个新的 Symfony4 项目并安装了 EasyAdmin 包(工作正常)。我尝试按照文档集成 CKeditor:https ://symfony.com/doc/master/bundles/EasyAdminBundle/integration/ivoryckeditorbundle.html
这是我的 easyadmin.yaml:
easy_admin:
entities:
TestPage:
class: App\Entity\TestPage
form:
fields:
- { property: 'content', type: 'fos_ckeditor', type_options: { 'config': { 'toolbar': [ { name: 'styles', items: ['Bold', 'Italic', 'BulletedList', 'Link'] } ] } }}
Run Code Online (Sandbox Code Playgroud)
这是我的 fos_ckeditor.yaml :
twig:
form_themes:
- '@FOSCKEditor/Form/ckeditor_widget.html.twig'
fos_ck_editor:
input_sync: true
default_config: base_config
configs:
base_config:
toolbar:
- { name: "styles", items: ['Bold', 'Italic', 'BulletedList', 'Link'] }
Run Code Online (Sandbox Code Playgroud)
问题是它仍然是显示的常规文本区域,而不是 ckeditor 富文本文本区域。
我试图清除缓存,在 twig.yaml 中添加“-'@FOSCKEditor/Form/ckeditor_widget.html.twig'”,但我仍然看不到 ckeditor 工具栏。任何人都知道我缺少什么?谢谢!
它在 EasyAdminBundle 文档上说
例如, index() 操作调用名为 createIndexQueryBuilder() 的方法来创建 Doctrine 查询构建器,用于获取显示在索引列表上的结果。如果您想自定义该列表,最好覆盖 createIndexQueryBuilder() 方法而不是整个 index() 方法。
因此,让我们想象一下,当用户被删除时,我的用户实体中的字段 isDeleted 设置为 true。在索引页面中,我只想显示 isDeleted = false 的用户。为此,如何覆盖 createIndexQueryBuilder()?
这是方法 createIndexQueryBuilder
public function createIndexQueryBuilder(SearchDto $searchDto, EntityDto $entityDto, FieldCollection $fields, FilterCollection $filters): QueryBuilder
{
return $this->get(EntityRepository::class)->createQueryBuilder($searchDto, $entityDto, $fields, $filters);
}
Run Code Online (Sandbox Code Playgroud)
我试图像这样覆盖它,但它没有用
public function createIndexQueryBuilder(SearchDto $searchDto, EntityDto $entityDto, FieldCollection $fields, FilterCollection $filters): QueryBuilder
{
$response = $this->get(EntityRepository::class)->createQueryBuilder($searchDto, $entityDto, $fields, $filters);
$response->where('isDeleted', true);
return $response;
}
Run Code Online (Sandbox Code Playgroud) 我正在使用 Symfony 5,并且已经安装了 easyAdmin 3.1 包。
它在我的本地主机中使用:
https://127.0.0.1:8000/admin
Run Code Online (Sandbox Code Playgroud)
但是,当我部署到我的 heroku 帐户时,访问 /admin 时出现错误:
404 : The requested URL was not found on this server.
Run Code Online (Sandbox Code Playgroud)
我的 heroku 应用网址是:
https://symfony-aristos.herokuapp.com/admin
事实上,这种情况发生在除 / 之外的任何 url 上。所以这与重定向有关。
https://symfony-aristos.herokuapp.com/login
在heroku日志中,我看到的是:
2020-11-25T07:58:41.279377+00:00 app[web.1]: 10.11.131.158 - - [25/Nov/2020:07:58:41 +0000] "GET /admin HTTP/1.1" 4604 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36
heroku 方面还缺少其他任何东西才能使其正常工作吗?
我想在创建新用户时使用 EasyAdmin 3.x 的验证组来验证每个字段。
\n我有一个包含name、phone和email字段的 User 实体,并在“创建”组中使用 @UniqueEntity ,因此我可以在 EasyAdmin 外部创建的表单中更新用户。这工作得很好,但当我使用新的组时,我无法找到如何告诉 EasyAdmin 使用默认组和我的创建组我的创建组。
\n这是带有我所具有的约束的简化用户实体
\nuse Doctrine\\ORM\\Mapping as ORM;\nuse Symfony\\Bridge\\Doctrine\\Validator\\Constraints\\UniqueEntity;\nuse Symfony\\Component\\Validator\\Constraints as Assert;\n\n/**\n * @ORM\\Entity(repositoryClass=LeadRepository::class)\n * @ORM\\HasLifecycleCallbacks()\n * @UniqueEntity(\n * fields="cellphone",\n * message="Ya existe un usuario con este n\xc3\xbamero telef\xc3\xb3nico",\n * groups={"creation"}\n * )\n * @UniqueEntity(\n * fields="email",\n * message="Ya existe un usuario con este email",\n * groups={"creation"}\n * )\n */\nclass Lead\n{\n /**\n * @ORM\\Id()\n * @ORM\\GeneratedValue()\n * @ORM\\Column(type="integer")\n …Run Code Online (Sandbox Code Playgroud) 我有一个非常基本的 symfony 5 + easyadmin 3 应用程序。我使用 make:entity 创建了两个实体:Posts 和 Categories
当我尝试编辑类别以分配帖子时,帖子未保存在数据库中。但是,如果我在帖子中添加类别,则将保存在 db 中。
知道我在这里缺少什么吗?
类别CrudController.php
public function configureFields(string $pageName): iterable
{
if (Crud::PAGE_EDIT === $pageName)
{
yield TextField::new('title');
yield DateTimeField::new('created_at')
->setFormTypeOption('disabled','disabled');
yield AssociationField::new('posts')
->autocomplete();
Run Code Online (Sandbox Code Playgroud)
实体类别.php
/**
* @ORM\OneToMany(targetEntity=Post::class, mappedBy="category")
*/
private $posts;
public function __construct()
{
$this->posts = new ArrayCollection();
}
/**
* @return Collection|Post[]
*/
public function getPosts(): Collection
{
return $this->posts;
}
public function addPost(Post $post): self
{
if (!$this->posts->contains($post)) {
$this->posts[] = $post;
$post->setCategory($this);
}
return …Run Code Online (Sandbox Code Playgroud)