We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phalcon complex sql query

Iam using phalcon-mvc-example multiple-service-layer-model in this link: https://github.com/phalcon/mvc/tree/master/multiple-service-layer-model it implement repository pattern. So when I create query at repository layer, I have only one choice is using EntityClass::find or EntityClass::query to build my sql query, I can't excute raw sql query using modelsManager because the repository layer not extend or implement any class of phalcon core. Any idea for this issue ????



58.4k
edited Nov '14

You want to use modelsManager, you just inseting it service.php

    $di->set(
    'modelsManager',
    function() {
        return new \Phalcon\Mvc\Model\Manager();
 });

Then using it in controller

    $phql = "UPDATE Phalcontip\ModelsJob SET Phalcontip\Models\Job.status = ?0 WHERE Phalcontip\Models\Job.id = ?1";
            $result = $this->modelsManager->executeQuery($phql, array(
                0 => Job::STATUS_DISPLAY,
                1 => $idJob
            ));

If you want to contribution question Phalcon forum Vietnam link here https://forum.zphalcon.com

Mình thực thi câu SQL từ tầng repository nên nó không gọi $this->modelsManager được đâu bạn :D