【问题标题】:Symfony schema:update errorSymfony 架构:更新错误
【发布时间】:2017-06-27 17:29:10
【问题描述】:

我有一个无法修复的错误,因为我找不到问题所在。 控制台中的错误说:

[Symfony\Component\Debug\Exception\FatalThrowableError]
Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting ',' or ';'

尝试使用时:

php bin/console doctrine:schema:update --dump-sql

我正在尝试为我的学习分配作业,但我找不到问题所在。 在实体“client_order.php”中添加下一个字段后,该命令不起作用:

/**
 * @ORM\ManyToOne(targetEntity="order_line")
 * @ORM\JoinColumn(name="order_line_id", referencedColumnName="id")
 */
private $order_line;

/**
 * @ORM\ManyToOne(targetEntity="user")
 * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
 */
private $user;

/**
 * @ORM\ManyToOne(targetEntity="Product")
 * @ORM\JoinColumn(name="Product_id", referencedColumnName="id")
 */
private $Product;

在 symfony 中添加新字段后,我使用了以下命令:

php bin/console doctrine:generate:entities TuinadviesBundle:client_order

这是完整的文档:

namespace TuinadviesBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* client_order
*
* @ORM\Table(name="client_order")
* @ORM\Entity(repositoryClass="TuinadviesBundle\Repository\client_orderRepository")
*/
class client_order
{
/**
 * @var int
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @var \DateTime
 *
 * @ORM\Column(name="date", type="date")
 */
private $date;

/**
 * @var \DateTime
 *
 * @ORM\Column(name="expiration_date", type="date")
 */
private $expirationDate;

/**
 * @ORM\ManyToOne(targetEntity="order_line")
 * @ORM\JoinColumn(name="order_line_id", referencedColumnName="id")
 */
private $order_line;

/**
 * @ORM\ManyToOne(targetEntity="user")
 * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
 */
private $user;

/**
 * @ORM\ManyToOne(targetEntity="Product")
 * @ORM\JoinColumn(name="Product_id", referencedColumnName="id")
 */
private $Product;

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

/**
 * Set date
 *
 * @param \DateTime $date
 *
 * @return client_order
 */
public function setDate($date)
{
    $this->date = $date;

    return $this;
}

/**
 * Get date
 *
 * @return \DateTime
 */
public function getDate()
{
    return $this->date;
}

/**
 * Set expirationDate
 *
 * @param \DateTime $expirationDate
 *
 * @return client_order
 */
public function setExpirationDate($expirationDate)
{
    $this->expirationDate = $expirationDate;

    return $this;
}

/**
 * Get expirationDate
 *
 * @return \DateTime
 */
public function getExpirationDate()
{
    return $this->expirationDate;
}

/**
 * Set orderLine
 *
 * @param \TuinadviesBundle\Entity\order_line $orderLine
 *
 * @return client_order
 */
public function setOrderLine(\TuinadviesBundle\Entity\order_line $orderLine = null)
{
    $this->order_line = $orderLine;

    return $this;
}

/**
 * Get orderLine
 *
 * @return \TuinadviesBundle\Entity\order_line
 */
public function getOrderLine()
{
    return $this->order_line;
}

/**
 * Set user
 *
 * @param \TuinadviesBundle\Entity\user $user
 *
 * @return client_order
 */
public function setUser(\TuinadviesBundle\Entity\user $user = null)
{
    $this->user = $user;

    return $this;
}

/**
 * Get user
 *
 * @return \TuinadviesBundle\Entity\user
 */
public function getUser()
{
    return $this->user;
}

/**
 * Set product
 *
 * @param \TuinadviesBundle\Entity\Product $product
 *
 * @return client_order
 */
public function setProduct(\TuinadviesBundle\Entity\Product $product = null)
{
    $this->Product = $product;

    return $this;
}

/**
 * Get product
 *
 * @return \TuinadviesBundle\Entity\Product
 */
public function getProduct()
{
    return $this->Product;
}
}

我添加的所有类都是正确的(即使是带有大写 P 的 Product(这是错误的))。

谁能告诉我我做错了什么?

提前致谢:)

【问题讨论】:

  • order_line 中的下划线将成为问题,所以它是 orderLine 看看是否可以解决它(包括在 getter/setter 中)
  • 感谢您的回复,但很遗憾没有成功:(
  • 您确定问题与这个特定的client_order 类有关吗?因为您还有至少 3 个其他实体并且尚未共享他们的代码。无论如何,您可以在详细模式下运行命令吗? php bin/console doctrine:schema:update --dump-sql -vvv 并分享输出?
  • 我想我是因为它在我添加这些之前就起作用了。但我会在一个新问题中发布它

标签: php symfony doctrine-orm many-to-one


【解决方案1】:

Jep 它在 user.php 我忘记了一个“;”但我可以发誓我没有编辑那个……哦,无论如何,谢谢:)

    C:\xampp\htdocs\tuinadvies>php bin/console doctrine:schema:update --dump-sql 
    -vvv
    21:50:41 INFO      [php] User Deprecated: The 
    "Symfony\Component\Console\Event\ConsoleExceptionEvent" class is deprecated 
    since version 3.3 and will be removed in 4.0. Use the ConsoleErrorEvent 
    instead.
    [
    "exception" => Symfony\Component\Debug\Exception\ContextErrorException {
    -context: [
      "class" => "Symfony\Component\Console\Event\ConsoleExceptionEvent",
      "file" => 

 "C:\xampp\htdocs\tuinadvies\vendor\composer/../symfony/symfony/src/Symfony/Component\Console\Event\ConsoleExceptionEvent.php"
    ],
    #message: "User Deprecated: The 
    "Symfony\Component\Console\Event\ConsoleExceptionEvent" class is deprecated since version 3.3 and will be removed in 4.0. Use the ConsoleErrorEvent instead.",
    #code: 0,
    #file: "C:\xampp\htdocs\tuinadvies\vendor\symfony\symfony\src\Symfony\Component\Console\Event\ConsoleExceptionEvent.php",
    #line: 14,
    #severity: E_USER_DEPRECATED,
    trace: {
      C:\xampp\htdocs\tuinadvies\vendor\symfony\symfony\src\Symfony\Component\Console\Event\ConsoleExceptionEvent.php:14: {
        : ,
        : @trigger_error(sprintf('The "%s" class is deprecated since version 3.3 and will be removed in 4.0. Use the ConsoleErrorEvent instead.', ConsoleExceptionEvent::class), E_USER_DEPRECATED);,
        :
      },
      C:\xampp\htdocs\tuinadvies\vendor\symfony\symfony\src\Symfony\Component\Debug\DebugClassLoader.php:144: {
        : if ($file = $this->classLoader[0]->findFile($class)) {,
        :     require_once $file;,
        : },
        arguments: {
          "C:\xampp\htdocs\tuinadvies\vendor\symfony\symfony\src\Symfony\Component\Console\Event\ConsoleExceptionEvent.php"
        }
      },
      Symfony\Component\Debug\DebugClassLoader->loadClass(): {},
      C:\xampp\htdocs\tuinadvies\vendor\symfony\symfony\src\Symfony\Component\Console\Application.php:897: {
        : $x = $e instanceof \Exception ? $e : new FatalThrowableError($e);,
        : $event = new ConsoleExceptionEvent($command, $input, $output, $x, $x->getCode());,
        : $this->dispatcher->dispatch(ConsoleEvents::EXCEPTION, $event);,
        arguments: {
          $class_name: "Symfony\Component\Console\Event\ConsoleExceptionEvent"
        }
      },
      C:\xampp\htdocs\tuinadvies\vendor\symfony\symfony\src\Symfony\Component\Console\Application.php:223: {
        : $this->runningCommand = $command;,
        : $exitCode = $this->doRunCommand($command, $input, $output);,
        : $this->runningCommand = null;,
        arguments: {
          $command: Doctrine\Bundle\DoctrineBundle\Command\Proxy\UpdateSchemaDoctrineCommand { …},
          $input: Symfony\Component\Console\Input\ArgvInput {#1 …},
          $output: Symfony\Component\Console\Output\ConsoleOutput {#2 …}
        }
      },
      C:\xampp\htdocs\tuinadvies\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Console\Application.php:81: {
        : ,
        :     return parent::doRun($input, $output);,
        : },
        arguments: {
          $input: Symfony\Component\Console\Input\ArgvInput {#1 …},
          $output: Symfony\Component\Console\Output\ConsoleOutput {#2 …}
        }
      },
      C:\xampp\htdocs\tuinadvies\vendor\symfony\symfony\src\Symfony\Component\Console\Application.php:130: {
        :     $e = null;,
        :     $exitCode = $this->doRun($input, $output);,
        : } catch (\Exception $x) {,
        arguments: {
          $input: Symfony\Component\Console\Input\ArgvInput {#1 …},
          $output: Symfony\Component\Console\Output\ConsoleOutput {#2 …}
        }
      },
      C:\xampp\htdocs\tuinadvies\bin\console:28: {
        : $application = new Application($kernel);,
        : $application->run($input);,
        : ,
        arguments: {
          $input: Symfony\Component\Console\Input\ArgvInput {#1 …}
        }
      }
    }
  }
]
[]


  [Symfony\Component\Debug\Exception\FatalThrowableError]
  Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting ',' or ';'


Exception trace:
 () at C:\xampp\htdocs\tuinadvies\src\TuinadviesBundle\Entity\user.php:108
 Doctrine\Common\Persistence\Mapping\Driver\AnnotationDriver->getAllClassNames() at C:\xampp\htdocs\tuinadvies\vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain.php:128
 Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain->getAllClassNames() at C:\xampp\htdocs\tuinadvies\vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory.php:114
 Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getAllMetadata() at C:\xampp\htdocs\tuinadvies\vendor\doctrine\orm\lib\Doctrine\ORM\Tools\Console\Command\SchemaTool\AbstractCommand.php:59
 Doctrine\ORM\Tools\Console\Command\SchemaTool\AbstractCommand->execute() at C:\xampp\htdocs\tuinadvies\vendor\doctrine\doctrine-bundle\Command\Proxy\UpdateSchemaDoctrineCommand.php:50
 Doctrine\Bundle\DoctrineBundle\Command\Proxy\UpdateSchemaDoctrineCommand->execute() at C:\xampp\htdocs\tuinadvies\vendor\symfony\symfony\src\Symfony\Component\Console\Command\Command.php:264
 Symfony\Component\Console\Command\Command->run() at C:\xampp\htdocs\tuinadvies\vendor\symfony\symfony\src\Symfony\Component\Console\Application.php:887
 Symfony\Component\Console\Application->doRunCommand() at C:\xampp\htdocs\tuinadvies\vendor\symfony\symfony\src\Symfony\Component\Console\Application.php:223
 Symfony\Component\Console\Application->doRun() at C:\xampp\htdocs\tuinadvies\vendor\symfony\symfony\src\Symfony\Bundle\FrameworkBundle\Console\Application.php:81
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at C:\xampp\htdocs\tuinadvies\vendor\symfony\symfony\src\Symfony\Component\Console\Application.php:130
 Symfony\Component\Console\Application->run() at C:\xampp\htdocs\tuinadvies\bin\console:28

doctrine:schema:update [--complete] [--dump-sql] [-f|--force] [--em [EM]] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多