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

Paginator join table

Hi, i have in my UserController.php a Paginator which works fine, but now i want to filter the users from another table "contact":

This is the code from my Users-Paginator:

 public function indexAction(){

    $numberPage = 1;
    if ($this->request->isPost()) {
        $query = Criteria::fromInput($this->di, 'Vokuro\Models\Users', $this->request->getPost());
        $this->persistent->searchParams = $query->getParams();
    } else {
        $numberPage = $this->request->getQuery("page", "int");
    }

    $parameters = array();
    if ($this->persistent->searchParams) {
        $parameters = $this->persistent->searchParams;
    }

    $users = Users::find($parameters);
    if (count($users) == 0) {
        $this->flash->notice("The search did not find any users");
        return $this->dispatcher->forward(array(
            "action" => "index"
        ));
    }

    $paginator = new Paginator(array(
        "data" => $users,
        "limit" => 10,
        "page" => $numberPage
    ));

    $this->view->page = $paginator->getPaginate();
}

In the contact table, ihave:

id
usersId
contacterId
insertDate

I want to list all the the users where the contact.usersId = users.id, but i don't know how to create it.

Thx in advance

Stefan :-)

Use Phalcon Model Manager for applying where clause in child table because find function does not support.

Example Query:

$users = $this->modelsManager->createBuilder() ->from(' users') ->innerjoin('contact') ->where('usersId = :usersId:', array('usersId' => $id)) ->getQuery()->execute();

and pass this $users to paginator function