小编Pie*_*aud的帖子

必须管理传递到选择字段的实体

我创建一个新对象并将其绑定到表单.用户填写表单并转到预览页面.我将用户响应存储在会话中.

当用户返回编辑表单时,当我尝试从会话重新加载对象时,问题就出现了.我得到的实体传递给选择字段必须是托管错误.

任何人都知道我可能会出错的地方?下面是控制器的代码.

public function previewdealAction(Request $request){

    $session = $this->getRequest()->getSession();
    $coupon = $session->get('coupon');
    $form = $this->createForm(new CouponType(), $coupon);

    if ($request->getMethod() == 'POST') {

        //bind the posted form values
        $form->bindRequest($request);

        //once a valid form is submitted ...
        if ($form->isValid()){
           //Proceed to Previewing deal
            $file = $coupon->getImage();
            $file->upload();
            $session->set('coupon', $coupon);

            $repository = $this->getDoctrine()
            ->getRepository('FrontendUserBundle:Coupon');
            $coupons = $repository->findAll();

            return $this->render('FrontendHomeBundle:Merchant:dealpreview.html.twig', array('coupon'=>$coupon, 'coupons'=>$coupons));

        }
    }

}
public function builddealAction(Request $request){

    $em = $this->get('doctrine')->getEntityManager();
    $user = $this->container->get('security.context')->getToken()->getUser();

    //check for a coupon session variable
    $session = …
Run Code Online (Sandbox Code Playgroud)

php symfony

22
推荐指数
3
解决办法
1万
查看次数

如何从 pyproject.toml 托管库的轮子中排除“tests”文件夹?

我尽力从setup.py托管库转移到纯pyproject.toml库。\n我有以下文件夹结构:

\n
tests\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 <files>\ndocs\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 <files>\nsepal_ui\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 <files>\npyproject.toml\n
Run Code Online (Sandbox Code Playgroud)\n

在我的pyproject.toml以下文件和包发现设置中:

\n
tests\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 <files>\ndocs\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 <files>\nsepal_ui\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 <files>\npyproject.toml\n
Run Code Online (Sandbox Code Playgroud)\n

在生产轮中,我得到以下信息:

\n
tests\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 <files>\ndocs\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 <files>\nsepal_ui\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 <files>\nsepal_ui.egg-info\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 top-level.txt\n
Run Code Online (Sandbox Code Playgroud)\n

查看 top-level.txt,我发现只包含 sepal_ui,所以我的问题很简单,为什么即使不使用额外的“docs”和“tests”文件夹,仍然包含它们?如何摆脱它们?

\n

PS:我知道 MANIFEST.in 解决方案,如果它确实是唯一的解决方案,我会接受它,但我发现在 2 个文件中指定是多余的。

\n

python setuptools pyproject.toml

7
推荐指数
1
解决办法
6955
查看次数

通过非主键 - id 的引用列名称连接列

我是 Symfony Doctrine 的新手,需要一些有关连接实体的帮助。

通常列是通过主键 ID 连接的

    /**
     * User
     *
     * @ORM\Table(name="users")
     * @ORM\Entity(repositoryClass="MainBundle\Repository\UserRepository")
     * UniqueEntity("email", message="Account with email already exists.")
     */
    class User implements AdvancedUserInterface, \Serializable
    {
    /**
         * @var \MainBundle\Entity\PersonDetails
         *
         * @ORM\ManyToOne(targetEntity="MainBundle\Entity\Person")
         * @ORM\JoinColumns({
         *  @ORM\JoinColumn(name="person_details_id", referencedColumnName="id", nullable=true)
         * })
         */
    private $personDetails = null;
Run Code Online (Sandbox Code Playgroud)

还行吧。

但问题是我想通过用户实体中的 id 字段连接关系 OneToOne 中的两列


    /**
     * User
     *
     * @ORM\Table(name="users")
     * @ORM\Entity(repositoryClass="MainBundle\Repository\UserRepository")
     * UniqueEntity("email", message="Account with email already exists.")
     */
    class User implements AdvancedUserInterface, \Serializable
    {
    /**
         * @var …
Run Code Online (Sandbox Code Playgroud)

symfony doctrine-orm

6
推荐指数
1
解决办法
9775
查看次数

如何转义 .rst 文件中的“`”反引号字符?

我想写下下面这句话:

Don't forget to escape the :code:`\`` character, it will be interpreted as code mark
Run Code Online (Sandbox Code Playgroud)

但我不知道如何转义“ `”反引号字符。有可能吗?

restructuredtext escaping backticks python-sphinx

6
推荐指数
1
解决办法
3191
查看次数

我在 python 中提取 rarfile 时遇到错误(找不到工作工具)

我想使用 python rarfile lib 提取 rarfile。这是我的代码

 import rarfile as rar
    def Extractor(extract_to_folder, file, base_file_path):  
        rar_ = rar.RarFile(base_file_path)
        rar_.extract(rar_, extract_to_folder)
        rar_.close()

Extractor('F:\MyFiles\myExFolder', 'howToAccess.txt', 'F:\MyFiles\River.rar')
Run Code Online (Sandbox Code Playgroud)

执行脚本后,出现以下错误:

raise RarCannotExec("找不到工作工具")
rarfile.RarCannotExec:找不到工作工具

python python-3.x

3
推荐指数
1
解决办法
5472
查看次数

使用 phpUnit 运行单个测试

我目前正在我的 Symfony 应用程序中引入测试。其中一些失败了,需要很长时间才能运行它们。

是否可以使用 simpl-phpunit 命令运行单个测试?

我已经测试过:

与我的测试的命名空间,但最终得到

./vendor/bin/simple-phpunit App\tests\Controller\DefaultControllerTest
Run Code Online (Sandbox Code Playgroud)

无法打开文件“ApptestsControllerDefaultControllerTest.php”。

并通过我的测试的相对路径,它会导致:

./vendor/bin/simple-phpunit tests/Controller/DefaultControllerTest
Run Code Online (Sandbox Code Playgroud)

无法打开文件“tests/Controller/DefaultControllerTest.php”。

php phpunit symfony simple-phpunit

2
推荐指数
1
解决办法
3359
查看次数

无法加载 Symfony\Bridge\Doctrine\RegistryInterface

我想在一台新计算机上使用我的应用程序,因此我从 Git 中提取了所有内容并重新启动composer,并yarn获取了所有第三方包和库。

运行时composer update出现以下错误:

无法自动装配服务“App\Repository\BlogPostRepository”:方法“__construct()”的参数“$registry”引用接口“Symfony\Bridge\Doctrine\RegistryInterface”,但不存在此类服务。尝试将类型提示更改为“Doctrine\Common\Persistence\ManagerRegistry”。

我的“BlogRepository”是

namespace App\Repository;

use App\Entity\BlogPost;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;

/**
 * @method BlogPost|null find($id, $lockMode = null, $lockVersion = null)
 * @method BlogPost|null findOneBy(array $criteria, array $orderBy = null)
 * @method BlogPost[]    findAll()
 * @method BlogPost[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
 */
class BlogPostRepository extends ServiceEntityRepository
{
    public function __construct(RegistryInterface $registry)
    {
        parent::__construct($registry, BlogPost::class);
    }
}
Run Code Online (Sandbox Code Playgroud)

它是由 symfony 自动生成的,我从未更改过它。这是一个错误还是改变了composer-update一切?

php symfony doctrine-orm composer-php

1
推荐指数
1
解决办法
6099
查看次数

只需单击Jquery即可提交多个具有相同名称的表单

嗨,我有循环中的表格,这是创造动态,我需要一次点击提交所有这些,我在下面的代码,请你建议我怎么能这样做谢谢

 <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                $("#submitButton").click(function () {
                    $.post($("#form1").attr("action"), $("#form1").serialize(),
                      function () {
                          alert('Form 1 submitted');
                      });

                    $.post($("#form2").attr("action"), $("#form1").serialize(),
                      function () {
                          alert('Form 2 submitted');
                      });
                });
            });
        </script>
    </head>
    <body>
        <form id="form1" action="PostPage1.aspx" method="post">
            <input type="button" id="submitButton" value="Submit" />
        </form>

        <!-- Hidden form -->
        <form id="form2" action="PostPage2.aspx" name= "formsub"  method="post">
            <input type="test" id="data1" value="testing1" />
            <input type="text" id="data2" value="testing2" />
        </form>

        <form id="form2" action="PostPage2.aspx" name= "formsub" method="post">
            <input type="test" id="data1" …
Run Code Online (Sandbox Code Playgroud)

php forms jquery submit

0
推荐指数
1
解决办法
6552
查看次数

为什么我无法使用 VichUploader 删除我的图像实体?

我使用 Symfony 4 和 Doctrine,并且使用 VichUploader 来管理我的图像。

我创建一个实体图像,当我使用这个实体添加新图像时,它就像一个魅力,但当我想用我的控制器删除它时:

    public function delete(Image $image):Response
    {
        $em = $this->getDoctrine()->getEntityManager();
        $em->remove($image);
        $em->flush();

        return new RedirectResponse($this->generateUrl('image-index'));
    }
Run Code Online (Sandbox Code Playgroud)

我收到最奇怪的错误:

Expected argument of type "string", "NULL" given at property path "fileName".
Run Code Online (Sandbox Code Playgroud)

在我的图像实体中,`文件名是这样的:

Expected argument of type "string", "NULL" given at property path "fileName".
Run Code Online (Sandbox Code Playgroud)

处理编辑实体时会出现相同的行为。你看到我做错了什么吗?

php symfony vichuploaderbundle

0
推荐指数
1
解决办法
1447
查看次数