facebook twitter hatena line email

Php/Symfony/Symfony2/doctrine/crud

提供: 初心者エンジニアの簡易メモ
2017年1月16日 (月) 23:29時点におけるAdmin (トーク | 投稿記録)による版

移動: 案内検索

dbに合わせたcontrollerを作成する(crud)

entityを作成した後controllerを作成するサンプルを以下に

entityをまずgenerateで作成

$ php app/console doctrine:generate:entity --entity="AcmeHelloBundle:Blog" --fields="name:string(255) description:text"

作られたphp -src/Acme/HelloBundle/Entity/Blog.php

namespace Acme\HelloBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
 * Blog
 *
 * @ORM\Table("blogs")
 * @ORM\Entity
 */
class Blog
{
   /**
    * @var integer
    *
    * @ORM\Column(name="id", type="integer")
    * @ORM\Id
    * @ORM\GeneratedValue(strategy="AUTO")
    */
   private $id;
   /**
    * @var string
    *
    * @ORM\Column(name="name", type="string", length=255)
    */
   private $name;
   /**
    * @var string
    *
    * @ORM\Column(name="description", type="text")
    */
   private $description;
   /**
    * Get id
    *
    * @return integer
    */
   public function getId()
   {
       return $this->id;
   }
   /**
    * Set name
    *
    * @param string $name
    * @return Blog
    */
   public function setName($name)
   {
       $this->name = $name;
       return $this;
   }
   /**
    * Get name
    *
    * @return string
    */
   public function getName()
   {
       return $this->name;
   }
   /**
    * Set description
    *
    * @param string $description
    * @return Blog
    */
   public function setDescription($description)
   {
       $this->description = $description;
       return $this;
   }
   /**
    * Get description
    *
    * @return string
    */
   public function getDescription()
   {
       return $this->description;
   }
}