自动生成crud后出错

时间:2017-11-06 14:53:56

标签: symfony

我通常不会使用自动工具生成控制器,但我想尝试运行

php bin/console generate:doctrine:crud   

运行良好

  CRUD generation  


  created ./src/AppBundle/Controller//TransactionController.php
  updated ./app/Resources/views/transaction/index.html.twig
  updated ./app/Resources/views/transaction/show.html.twig
  updated ./app/Resources/views/transaction/new.html.twig
  updated ./app/Resources/views/transaction/edit.html.twig
  created ./src/AppBundle/Tests/Controller/
  created ./src/AppBundle/Tests/Controller//TransactionControllerTest.php
  created ./src/AppBundle/Resources/config/routing/
  created ./src/AppBundle/Resources/config/routing/transaction.php
Generating the CRUD code: OK
  created ./src/AppBundle/Form/
  created ./src/AppBundle/Form/TransactionType.php
Generating the Form code: OK
Updating the routing: Confirm automatic update of the Routing [yes]? yes
Importing the CRUD routes:   created ./src/AppBundle/Resources/config/routing.yml
  updated ./app/config/routing.yml
OK


  Everything is OK! Now get to work :).  

然而,之后我尝试安装了一个编写器包,我收到了这些错误。

 [Symfony\Component\Config\Exception\FileLoaderLoadException]                 
  The autoloader expected class "AppBundle\Resources\config\routing\transacti  
  on" to be defined in file "/Users/dash/AdvisorEngine/vendor/compos  
  er/../../src/AppBundle/Resources/config/routing/transaction.php". The file   
  was found but the class was not in it, the class name or namespace probably  
   has a typo in /Users/dash/AdvisorEngine/app/config/services.yml (  
  which is being imported from "/Users/dash/AdvisorEngine/app/config  
  /config.yml").                                                               



  [RuntimeException]                                                           
  The autoloader expected class "AppBundle\Resources\config\routing\transacti  
  on" to be defined in file "/Users/dash/AdvisorEngine/vendor/compos  
  er/../../src/AppBundle/Resources/config/routing/transaction.php". The file   
  was found but the class was not in it, the class name or namespace probably  
   has a typo.

配置/ routing.yml中

app:
    resource: "@AppBundle/Resources/config/routing.yml"
    prefix:   /

的appbundle /资源/配置/ routing.yml中

app_transaction:
resource: "@AppBundle/Resources/config/routing/transaction.php"
prefix:   /transaction

的appbundle /资源/配置/路由/ transaction.php

<?php

use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;

$collection = new RouteCollection();

$collection->add('transaction_index', new Route(
    '/',
    array('_controller' => 'AppBundle:Transaction:index'),
    array(),
    array(),
    '',
    array(),
    array('GET')
));

$collection->add('transaction_show', new Route(
    '/{id}/show',
    array('_controller' => 'AppBundle:Transaction:show'),
    array(),
    array(),
    '',
    array(),
    array('GET')
));

$collection->add('transaction_new', new Route(
    '/new',
    array('_controller' => 'AppBundle:Transaction:new'),
    array(),
    array(),
    '',
    array(),
    array('GET', 'POST')
));

$collection->add('transaction_edit', new Route(
    '/{id}/edit',
    array('_controller' => 'AppBundle:Transaction:edit'),
    array(),
    array(),
    '',
    array(),
    array('GET', 'POST')
));

$collection->add('transaction_delete', new Route(
    '/{id}/delete',
    array('_controller' => 'AppBundle:Transaction:delete'),
    array(),
    array(),
    '',
    array(),
    array('DELETE')
));

return $collection;

的appbundle:事务

<?php
namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="transactions")
 */
class Transaction
{
    const OPERATION_BUY = 'buy';
    const OPERATION_SELL = 'sell';

    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\Column(type="date")
     */
    private $date;

    /**
     * @ORM\ManyToOne(targetEntity="Stock")
     * @ORM\JoinColumn(name="stock_id", referencedColumnName="id")
     */
    private $stock;

    /** @ORM\Column(type="string") */
    private $operation;

    /**
     * @ORM\Column(type="integer")
     */
    private $amount;

    /**
     * @ORM\Column(type="decimal", precision=7, scale=2)
     */
    private $unitPrice;

    /**
     * @ORM\Column(type="decimal", precision=10, scale=2)
     */
    private $price;

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

    /**
     * @param mixed $id
     */
    public function setId($id)
    {
        $this->id = $id;
    }

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

    /**
     * @param mixed $date
     */
    public function setDate($date)
    {
        $this->date = $date;
    }

    /**
     * @return mixed
     */
    public function getStock()
    {
        return $this->stock;
    }

    /**
     * @param mixed $stock
     */
    public function setStock($stock)
    {
        $this->stock = $stock;
    }

    /**
     * @return mixed
     */
    public function getamount()
    {
        return $this->amount;
    }

    /**
     * @param mixed $amount
     */
    public function setamount($amount)
    {
        $this->amount = $amount;
    }

    /**
     * @return mixed
     */
    public function getUnitPrice()
    {
        return $this->unitPrice;
    }

    /**
     * @param mixed $unitPrice
     */
    public function setUnitPrice($unitPrice)
    {
        $this->unitPrice = $unitPrice;
    }

    /**
     * @return mixed
     */
    public function getPrice()
    {
        return $this->price;
    }

    /**
     * @param mixed $price
     */
    public function setPrice($price)
    {
        $this->price = $price;
    }

    /**
     * @return mixed
     */
    public function getOperation()
    {
        return $this->operation;
    }

    /**
     * @param string $operation
     */
    public function setOperation($operation)
    {
        if (!in_array($operation, [ self::OPERATION_BUY, self::OPERATION_SELL])) {
            $this->operation = $operation;
        }
    }
}

为什么期望路由课程?

1 个答案:

答案 0 :(得分:1)

基于这一行:

created ./src/AppBundle/Resources/config/routing/transaction.php

我怀疑你没有在代码中的某个地方为transaction.php定义正确的路径,而crud生成器正在错误的位置构建这个文件。

相关问题