이것이 가능한지 확실하지 않지만 쿼리에서 교리 컬렉션을 만들려고합니다. 아이디어는 일부 사전 설정 값으로 컬렉션을 채우는 것입니다. 그래서 데이터베이스를 업데이트 할 수 있습니다. 기존 시스템에서 새 시스템으로 사용자를 가져 오거나 생성하는 것처럼 생각할 수 있습니다. Im은 저장소 비트로 어려움을 겪고 있습니다. 컨트롤러와symfony2 쿼리에서 doctrine 콜렉션을 생성하십시오.
내부를 호출
엔티티
// Portal\UserBundle\Entity\User.php
namespace Portal\UserBundle\Entity;
use Doctrine\ORM\Mapping AS ORM;
/**
* @ORM\Entity
*/
class User
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=false)
*/
private $fistname;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
// etc...
}
저장소
namespace Portal\UserBundle\Entity\Repository;
use Doctrine\ORM\EntityRepository;
class UserRepository extends EntityRepository
{
public function getGenerateNewUsers()
{
// acts as an import from an old user table
$sql = " SELECT firstname, surname, other FROM old_user_table ";
$userCollection = .... not sure how I link query?
return $userCollection;
}
}
는 I 상기 새로 생성 된 사용자 루프를 페치 할 수 있도록하려는 그들과 acce있다 내 엔티티 방법에 SS는
class SetupController extends Controller
{
public function indexAction(){
$repository = this->getDoctrine()->getRepository('UserBundle:User');
$newUsers = $repository->getGenerateUsers();
// I can now have access to the users with something like
foreach($newUsers as $user){
$user->setFirstName('testing');
$user->save();
}
}
}
http://symfony.com/doc/current/bundles/DoctrineFixturesBundle/index.html을 보셨습니까? – cheesemacfly
링크를 주셔서 감사하지만 여전히 쿼리에서 직접 교리 객체를 생성 할 수 있기를 원하십니까? 그것을하는 방법을 아는 것은 손잡이 일 것입니다. –