Last active
March 1, 2016 21:10
-
-
Save index0h/cadac134cd2e535e2916 to your computer and use it in GitHub Desktop.
symfony_example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
account_repository: | |
class: MY\AppBundle\Repository\AccountRepository | |
factory: ["@doctrine", getRepository] | |
arguments: | |
- MY\AppBundle\Entity\Account |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace MY\AppBundle\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
/** | |
* @ORM\Table( | |
* name="account", | |
* indexes={ | |
* @ORM\Index( | |
* name="createdAt", | |
* columns={"createdAt"} | |
* ) | |
* } | |
* ) | |
* @ORM\Entity(repositoryClass="MY\AppBundle\Repository\AccountRepository") | |
*/ | |
class Account | |
{ | |
/** | |
* @var int | |
* @ORM\Column(name="id", type="integer") | |
* @ORM\Id | |
* @ORM\GeneratedValue(strategy="IDENTITY") | |
*/ | |
private $id; | |
/** | |
* @var \DateTime | |
* @ORM\Column(name="createdAt", type="datetime", nullable=false) | |
*/ | |
private $createdAt; | |
/** | |
* @return int | |
*/ | |
public function getId() | |
{ | |
return $this->id; | |
} | |
/** | |
* @return \DateTimeImmutable | |
*/ | |
public function getCreatedAt() | |
{ | |
return $this->createdAt; | |
} | |
/** | |
* @param \DateTime $createdAt | |
* @return $this | |
*/ | |
public function setCreatedAt(\DateTime $createdAt) | |
{ | |
$this->createdAt = $createdAt; | |
return $this; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace MY\AppBundle\Repository; | |
use Doctrine\ORM\EntityRepository; | |
class AccountRepository extends EntityRepository | |
{ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE IF NOT EXISTS `balance` ( | |
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT, | |
`createdAt` TIMESTAMP NOT NULL, | |
PRIMARY KEY (`id`), | |
INDEX `createdAt` (`createdAt` ASC) | |
) | |
ENGINE = InnoDB | |
DEFAULT CHARACTER SET = utf8 | |
COLLATE = utf8_general_ci; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
см. http://symfony.com/doc/current/book/doctrine.html#add-mapping-information
Далее в контроллерах например можешь дергать репозиторий так:
или так
С Entity работаем следующим образом: