0

View in database I mean :

create view `vMaketType` as select * from MaketType

I have a view in database, but because of doctrine cant support it now, i using query, and fetch it one by one :

        $em = $this->getDoctrine()->getManager();
        $con = $this->getDoctrine()->getEntityManager()->getConnection();
        $stmt = $con->executeQuery('SELECT * FROM vMaketType');
        $domain = [];
        //I must fetch it and set it one by one
        foreach ($stmt->fetchAll() as $row){
           $obj = new vMaketType();
           $obj->setId($row["Id"]);
           $obj->setName($row["Name"]);
           $obj->setAmount($row["Amount"]);
           array_push($domain, $obj);
        }

for me this is really takes too much time to code one by one.

vMaketType is a custom entity I created to send data from controller to [Twig]view.

is there any easier way to fetch to array of object vMaketType?

because I have a view with 24 fields, I wish there is easier way for it.

4
  • Why don't you just use MarketType (I'm assuming that's your entity with mapping information)? Commented Nov 4, 2017 at 10:19
  • He says it doesn't work with sql views, but I don't see why: Check out: stackoverflow.com/questions/8377671/… Commented Nov 4, 2017 at 10:29
  • I use ORM generate schema Commented Nov 5, 2017 at 12:26
  • So what did you do? Commented Nov 13, 2017 at 11:22

1 Answer 1

0

Perhaps you can try with the serializer:

$obj = $this->get('serializer')->deserialize($row, 'Namespace\MaketType', 'array');

Code not tested, tweaks may be done, see the related doc.

Sign up to request clarification or add additional context in comments.

2 Comments

I've been read it, but it cant works for view, that's why I used handcoded query. :) you should read my explanation first, or cmiiw if there is any way orm doctrine support view
cmon, bro, you dont understand what i ask

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.