在Symfony2中嵌入一个集合类型(Embed a collection type in Symfony2)

试图嵌入一个集合类型,基本上遵循这里的一步一步的方法。

我收到以下错误:

The form's view data is expected to be an instance of class
AppBundle\Entity\BenefitGroup, but is an instance of class 
AppBundle\Entity\BenefitItem. You can avoid this error by setting the 
"data_class" option to null or by adding a view transformer that transforms 
an instance of class AppBundle\Entity\BenefitItem to an instance of 
AppBundle\Entity\BenefitGroup.

只是为了澄清,BenefitItem是父亲,而BenefitGroup是孩子。

我基本上得到了这个错误。

我还没有实现(还)允许你动态添加BenefitGroup元素的部分,我甚至没有尝试持久化对象或删除它(所以我没有实现Doctrine的最后一部分,如例)。

这是我的代码:

BenefitItem实体:

<?php
// src/AppBundle/Entity/BenefitItem.php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * @ORM\Entity(repositoryClass="AppBundle\Entity\BenefitItemRepository")
 * @ORM\Table(name="benefit_items")
 */
class BenefitItem
{
/**
 * @ORM\Column(type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

/**
 * @ORM\Column(type="string", length=400)
 */
protected $comment;

public function __construct()
{
    $this->BenefitGroups = new ArrayCollection();
}

public function getBenefitGroups()
{
    return $this->BenefitGroups;
}

/**
 * Get id
 *
 * @return integer 
 */
public function getId()
{
    return $this->id;
}

/**
 * Set comment
 *
 * @param string $comment
 * @return BenefitItem
 */
public function setComment($comment)
{
    $this->comment = $comment;

    return $this;
}

/**
 * Get comment
 *
 * @return string 
 */
public function getComment()
{
    return $this->comment;
}
}

BenefitGroup实体:

<?php
// src/AppBundle/Entity/BenefitGroup.php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass="AppBundle\Entity\BenefitGroupRepository")
 * @ORM\Table(name="benefit_groups")
 */
class BenefitGroup
{
/**
 * @ORM\Column(type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

/**
 * @ORM\Column(type="string", length=100)
 */
protected $name;

/**
 * @ORM\ManyToOne(targetEntity="BenefitItem", cascade={"persist"})
 * @ORM\JoinColumn(name="benefitItem_id")
 */
protected $benefitItem;


/**
 * Get id
 *
 * @return integer 
 */
public function getId()
{
    return $this->id;
}

/**
 * Set name
 *
 * @param string $name
 * @return BenefitGroup
 */
public function setName($name)
{
    $this->name = $name;

    return $this;
}

/**
 * Get name
 *
 * @return string 
 */
public function getName()
{
    return $this->name;
}

/**
 * Set benefitItem
 *
 * @param \AppBundle\Entity\BenefitItem $benefitItem
 * @return BenefitGroup
 */
public function setBenefitItem(\AppBundle\Entity\BenefitItem $benefitItem = null)
{
    $this->benefitItem = $benefitItem;

    return $this;
}

/**
 * Get benefitItem
 *
 * @return \AppBundle\Entity\BenefitItem 
 */
public function getBenefitItem()
{
    return $this->benefitItem;
}
}

BenefitItemFormType:

<?php

namespace AppBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class BenefitItemFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder->add('comment');

    $builder->add('benefitgroups', 'collection', array('type' => new BenefitGroupFormType()));
}

public function setDefaultOptions(OptionsResolverInterface $resolver)
{
    $resolver->setDefaults(array(
        'data_class' => 'AppBundle\Entity\BenefitGroup',
    ));
}

public function getName()
{
    return 'BenefitItem';
}
}

BenefitGroupFormType:

<?php

namespace AppBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class BenefitGroupFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder->add('name');
}

public function setDefaultOptions(OptionsResolverInterface $resolver)
{
    $resolver->setDefaults(array(
        'data_class' => 'AppBundle\Entity\BenefitGroup',
    ));
}

public function getName()
{
    return 'BenefitGroup';
}
}

控制器:

<?php
// AppBundle\Controller\BenefitController.php

namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use AppBundle\Entity\BenefitItem;
use AppBundle\Entity\BenefitGroup;
use AppBundle\Form\Type\BenefitItemFormType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class BenefitController extends Controller
{
/**
 * @Route("/benefit/show", name="benefit_show")
 */
public function showAction(Request $request)
{
    $BI = new BenefitItem();

    $BG1 = new BenefitGroup();
    $BG1->setName = 'Name 1';
    $BI->getBenefitGroups()->add($BG1);
    $BG2 = new BenefitGroup();
    $BG2->setName = 'Name 2';
    $BI->getBenefitGroups()->add($BG2);        

    $form = $this->createForm(new BenefitItemFormType(), $BI);

    $form->handleRequest($request);

    if ($form->isValid()) {
        // ... maybe do some form processing, like saving the Task and Tag objects
    }

    return $this->render('benefit/show.html.twig', array(
        'form' => $form->createView(),
    ));
}
}

任何想法?


Trying to embed a collection type, basically following the step by step approach here.

I get the following error:

The form's view data is expected to be an instance of class
AppBundle\Entity\BenefitGroup, but is an instance of class 
AppBundle\Entity\BenefitItem. You can avoid this error by setting the 
"data_class" option to null or by adding a view transformer that transforms 
an instance of class AppBundle\Entity\BenefitItem to an instance of 
AppBundle\Entity\BenefitGroup.

Just to clarify, the BenefitItem is the father while the BenefitGroup is the child.

I'm getting this error, basically.

I've not implemented (yet) the part that allows you to add BenefitGroup elements dynamically, and I'm not even trying to persist the object or remove it (so I did not implement yet the last part of the Doctrine as explained in the example).

Here is my code:

The BenefitItem entity:

<?php
// src/AppBundle/Entity/BenefitItem.php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;

/**
 * @ORM\Entity(repositoryClass="AppBundle\Entity\BenefitItemRepository")
 * @ORM\Table(name="benefit_items")
 */
class BenefitItem
{
/**
 * @ORM\Column(type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

/**
 * @ORM\Column(type="string", length=400)
 */
protected $comment;

public function __construct()
{
    $this->BenefitGroups = new ArrayCollection();
}

public function getBenefitGroups()
{
    return $this->BenefitGroups;
}

/**
 * Get id
 *
 * @return integer 
 */
public function getId()
{
    return $this->id;
}

/**
 * Set comment
 *
 * @param string $comment
 * @return BenefitItem
 */
public function setComment($comment)
{
    $this->comment = $comment;

    return $this;
}

/**
 * Get comment
 *
 * @return string 
 */
public function getComment()
{
    return $this->comment;
}
}

The BenefitGroup entity:

<?php
// src/AppBundle/Entity/BenefitGroup.php

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass="AppBundle\Entity\BenefitGroupRepository")
 * @ORM\Table(name="benefit_groups")
 */
class BenefitGroup
{
/**
 * @ORM\Column(type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $id;

/**
 * @ORM\Column(type="string", length=100)
 */
protected $name;

/**
 * @ORM\ManyToOne(targetEntity="BenefitItem", cascade={"persist"})
 * @ORM\JoinColumn(name="benefitItem_id")
 */
protected $benefitItem;


/**
 * Get id
 *
 * @return integer 
 */
public function getId()
{
    return $this->id;
}

/**
 * Set name
 *
 * @param string $name
 * @return BenefitGroup
 */
public function setName($name)
{
    $this->name = $name;

    return $this;
}

/**
 * Get name
 *
 * @return string 
 */
public function getName()
{
    return $this->name;
}

/**
 * Set benefitItem
 *
 * @param \AppBundle\Entity\BenefitItem $benefitItem
 * @return BenefitGroup
 */
public function setBenefitItem(\AppBundle\Entity\BenefitItem $benefitItem = null)
{
    $this->benefitItem = $benefitItem;

    return $this;
}

/**
 * Get benefitItem
 *
 * @return \AppBundle\Entity\BenefitItem 
 */
public function getBenefitItem()
{
    return $this->benefitItem;
}
}

The BenefitItemFormType:

<?php

namespace AppBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class BenefitItemFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder->add('comment');

    $builder->add('benefitgroups', 'collection', array('type' => new BenefitGroupFormType()));
}

public function setDefaultOptions(OptionsResolverInterface $resolver)
{
    $resolver->setDefaults(array(
        'data_class' => 'AppBundle\Entity\BenefitGroup',
    ));
}

public function getName()
{
    return 'BenefitItem';
}
}

The BenefitGroupFormType:

<?php

namespace AppBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class BenefitGroupFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder->add('name');
}

public function setDefaultOptions(OptionsResolverInterface $resolver)
{
    $resolver->setDefaults(array(
        'data_class' => 'AppBundle\Entity\BenefitGroup',
    ));
}

public function getName()
{
    return 'BenefitGroup';
}
}

The controller:

<?php
// AppBundle\Controller\BenefitController.php

namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use AppBundle\Entity\BenefitItem;
use AppBundle\Entity\BenefitGroup;
use AppBundle\Form\Type\BenefitItemFormType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class BenefitController extends Controller
{
/**
 * @Route("/benefit/show", name="benefit_show")
 */
public function showAction(Request $request)
{
    $BI = new BenefitItem();

    $BG1 = new BenefitGroup();
    $BG1->setName = 'Name 1';
    $BI->getBenefitGroups()->add($BG1);
    $BG2 = new BenefitGroup();
    $BG2->setName = 'Name 2';
    $BI->getBenefitGroups()->add($BG2);        

    $form = $this->createForm(new BenefitItemFormType(), $BI);

    $form->handleRequest($request);

    if ($form->isValid()) {
        // ... maybe do some form processing, like saving the Task and Tag objects
    }

    return $this->render('benefit/show.html.twig', array(
        'form' => $form->createView(),
    ));
}
}

Any idea?


原文:https://stackoverflow.com/questions/29260595
2020-01-01 07:15

满意答案

从图像看起来你想要一个支点,我相信你通过做到这一点来实现这一点

SELECT a.userid, u.name, u.profilePic,
    SUM(activity_weight) total_points,
    SUM(CASE WHEN activity_typeid=22 THEN activity_weight ELSE 0 END) activity22,
    SUM(CASE WHEN activity_typeid=33 THEN activity_weight ELSE 0 END) activity33,
    SUM(CASE WHEN activity_typeid=55 THEN activity_weight ELSE 0 END) activity55    
FROM activity_entries a 
INNER JOIN users1 u ON u.id = a.userid 
WHERE competitionId = '$competitionId' 
GROUP BY a.userid 
ORDER BY totalPoints

编辑注释:以下可能存在一些语法错误,但想法是动态创建sql然后执行它

-- generate sql for pivoted columns
SET @sql = NULL;
SELECT
  GROUP_CONCAT(DISTINCT
    CONCAT(
      'SUM(CASE WHEN activity_typeid=',activity_typeid,
      ' THEN activity_weight ELSE 0 END) AS activity_', activity_typeid, 
    )
  ) INTO @sql
FROM activity_entries;

-- place above in full select query
-- n.b. the `$competitionId` could be a problem my MySQL is not v. good
SET @sql = CONCAT('SELECT a.userid, u.name, u.profilePic,
                          SUM(activity_weight) total_points,', @sql,
                  'FROM activity_entries 
                   JOIN users1 u ON u.id = a.userid 
                   WHERE competitionId = ''$competitionId''   
                   GROUP BY a.userid, u.name, u.profilePic
                   ORDER BY totalPoints');

-- execute the dynamic sql
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

From the image it looks like you want a pivot, I believe in MySQL you achieve this by doing

SELECT a.userid, u.name, u.profilePic,
    SUM(activity_weight) total_points,
    SUM(CASE WHEN activity_typeid=22 THEN activity_weight ELSE 0 END) activity22,
    SUM(CASE WHEN activity_typeid=33 THEN activity_weight ELSE 0 END) activity33,
    SUM(CASE WHEN activity_typeid=55 THEN activity_weight ELSE 0 END) activity55    
FROM activity_entries a 
INNER JOIN users1 u ON u.id = a.userid 
WHERE competitionId = '$competitionId' 
GROUP BY a.userid 
ORDER BY totalPoints

Edit for comments: there may be some syntax errors in the following but the idea is to create the sql dynamically and then execute it

-- generate sql for pivoted columns
SET @sql = NULL;
SELECT
  GROUP_CONCAT(DISTINCT
    CONCAT(
      'SUM(CASE WHEN activity_typeid=',activity_typeid,
      ' THEN activity_weight ELSE 0 END) AS activity_', activity_typeid, 
    )
  ) INTO @sql
FROM activity_entries;

-- place above in full select query
-- n.b. the `$competitionId` could be a problem my MySQL is not v. good
SET @sql = CONCAT('SELECT a.userid, u.name, u.profilePic,
                          SUM(activity_weight) total_points,', @sql,
                  'FROM activity_entries 
                   JOIN users1 u ON u.id = a.userid 
                   WHERE competitionId = ''$competitionId''   
                   GROUP BY a.userid, u.name, u.profilePic
                   ORDER BY totalPoints');

-- execute the dynamic sql
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

相关问答

更多

SQLite选择哪里空?(SQLite select where empty?)

有几种方法,如: where some_column is null or some_column = '' 要么 where ifnull(some_column, '') = '' 要么 where coalesce(some_column, '') = '' 的 where ifnull(length(some_column), 0) = 0 There are several ways, like: where some_column is null or some_column ...

我的SQL Fiddle查询出了什么问题?(What's wrong with my SQL Fiddle query?)

对于那些对SQL Fiddle我一直在处理的一些神秘问题感兴趣的人的一些背景知识: 禁用JDBC中的显式提交,在SQL中检测它们,或将数据库置于只读状态 (dba.se) 从本质上讲,我试图确保小提琴始终保持一致状态,即使人们玩它们也是如此。 我担心的一件事是人们故意弄乱数据库,打破了可能与他们一起工作的其他人(这种情况以前发生过,但通常不幸见)。 我已经找到了为每个数据库平台保持清洁的方法,但有趣的是每个平台的每个方法都完全不同。 不幸的是,对于MySQL,我不得不求助于最糟糕的选择 - 只允许...

如何对sum的数据帧进行采样,其中sum与列总和部分匹配(How to sample dataframe where sum matches partially with column sum)

像这样的东西? id = c(123,234,345,124,111,116) sum = c(12,12,50,23,20,20) df = data.frame("id" = id, "sum"=sum) df[cumsum(df$sum) <110,] # id sum #1 123 12 #2 234 12 #3 345 50 #4 124 23 Something like this? id = c(123,234,345,124,111,116) sum = c(12,1...

允许参数化SQL查询的哪些部分?(What parts of a SQL query are allowed to be parameterized?)

标识符和关键字不可参数化。 这包括: 列名称 表名 架构名称 数据库名称 运营商 功能名称 关键词 基本思想是编译查询,编译版本有参数。 缺少任何上述元素时,无法编译查询。 Identifiers and keywords are not parameterizable. This includes: Columns names Table names Schema names Database names Operators Function names Keywords The basic i...

在MYSQL中使用WHERE时,我可以使用多个参数吗?(Can I use multiple parameters when using WHERE in MYSQL)

是的,只需将它们与AND分开: WHERE some_column=some_value AND other_column=other_value Yes, just separate them with ANDs: WHERE some_column=some_value AND other_column=other_value

在DB2 sql for z / os中使用0填充smallint(pad smallint with 0s in DB2 sql for z/os)

在所有当前支持的DB2 for z / OS版本中,都有一个功能DIGITS()可以完全满足您的需求。 In all currently supported versions of DB2 for z/OS there's a function DIGITS() that does exactly what you need.

SUM(some_column)WHERE some_column匹配(SUM (some_column) WHERE some_column matches)

从图像看起来你想要一个支点,我相信你通过做到这一点来实现这一点 SELECT a.userid, u.name, u.profilePic, SUM(activity_weight) total_points, SUM(CASE WHEN activity_typeid=22 THEN activity_weight ELSE 0 END) activity22, SUM(CASE WHEN activity_typeid=33 THEN activity_weight E...

dropColumn布尔变量时,liquibase迁移失败(liquibase migration failed while dropColumn boolean variable)

SOME_TABLE通过从其中删除some_column来修改SOME_TABLE 然后在同一个changeSet中,我修改了VIEW表,它具有旧的some_column值,因为它不再需要 我得到异常的原因是因为当从表中删除列时,查看表仍然持有它并且不让它掉落 我如何解决它: 首先通过删除some_column变量来修改视图表 然后从SOME_TABLE删除some_column The changeSet consisted of modifying the SOME_TABLE by drop...

我应该在使用字符串替换进行更新时添加WHERE子句(Should I add a WHERE clause when updating with string replacements)

如果在表上定义了BEFORE / AFTER UPDATE触发器,则查询的不同之处在于是否为表中的所有行触发了触发器,或者仅触发了WHERE子句中满足谓词的行。 否则,在MySQL中,这两个查询是等价的。 如果分配给列的值与列中已有的值相同,则MySQL不会将行计数(或报告)为受UPDATE“影响”。 (其他关系数据库会对“受影响”计数中的行进行计数。 由于LIKE比较中的前导百分号,需要对表中的每一行评估该条件,因此性能不会有任何差异。 如果some_records(some_column)上有...

根据多列匹配(一些部分)总结一列(Sum up a column based on multiple column matches (some partial))

拯救! $ awk '{a[$2 FS substr($5,1,4)]+=$1} END {for(k in a) print a[k],k}' file | sort -k3n -k2,2M 16180725217 May 2016 20543202693 May 2017 awk to the rescue! $ awk '{a[$2 FS substr($5,1,4)]+=$1} END {for(k in a) print a[k],k}' file |...

相关文章

更多

Symfony2网站开发

http://blog.csdn.net/liubei5/article/details/132902 ...

ServletOutputStream cannot be resolved to a type

在使用jsp生成web图片时遇到这个问题,这是源代码中的一条语句,源代码可以执行,可是一将源码放入ec ...

Hibernate 异常之:associate a collection with two ...

Hibernate exception - Illegal attempt to associate ...

用好Collection 对solrj入库进行优化

今天一个朋友找我说他进行入库测试: 1个collection 2个shard,30多个字段,一个小时才 ...

英语谚语精选(English Proverb Collection)

Lying is the first step to the gallows. 说谎是上断头台的第 ...

Solr参数(Analysis Collection Common CoreAdmin)

一.Analysis 1.analysis.query:Holds the query to be a ...

Spring Data: a new perspective of data operations

Spring Data: a new perspective of data operations ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本