Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How make "inner join" with Phalcon?

Hello! After so much analysis and to have used other frameworks I have had a real challenge and I have decided to use Phalcon and it has blown my head! Is so efficient that it leaves behind any other framework.

Well there is something that is not working for me and it is that I need to do "inner join" in my querys and I do not find the return. I have this structure: App / App / controllers / IndexController.php App / controllers / TUserController.php App / models / TUser.php

In the document Explains ModelsManager but I can not locate the code in the controller

To do this query: "select * from t_user"; Code fragments: <? Php

Use Phalcon \ Mvc \ Model \ Criteria;

Use Phalcon \ Paginator \ Adapter \ Model as Paginator;

Use Phalcon \ Di;

Use Phalcon \ Mvc \ Model \ Manager as ModelsManager;

Class TUserController extends ControllerBase {     Public function indexAction () { $ Di = new Di ();

        $ Di-> set ( "ModelsManager", Function () { Return new ModelsManager (); } ); $ TUser = new TUser ($ di);

        $ Query = new Phalcon \ Mvc \ Model \ Query ("SELECT * FROM t_user", $ di); $ TUsers = $ query-> execute (); $ This-> persistent-> parameters = null; }

Well I seem to have responded by myself, but I swear I've done this before.


use LoginForm as FormLogin; use TUser as TUser; use Phalcon\Mvc\Model\Query; use Phalcon\Di; use Phalcon\Mvc\Model\Manager as ModelsManager;

class IndexController extends ControllerBase {

public function indexAction() {
    $email = $this->request->getPost('email', array('striptags', 'trim')); //, 'email'
    $password = $this->request->getPost('password', array('striptags', 'trim'));
    //OPTION 1 OK 
    // Instantiate the Query
    $query = new Query(
        "SELECT * FROM TUser", $this->getDI()

// // Execute the query returning a result if any $TUser = $query->execute();

    //OPTION 2 OK
    $di = new Di();

            "modelsManager", function() {
        return new ModelsManager();

// Executing a simple query $query = $this->modelsManager->createQuery("SELECT * FROM TUser"); $cars = $query->execute(); var_dump($cars); die;

edited Mar '17

Hi, to join SQL queries I use:

 $db = \Phalcon\DI::getDefault()->getShared('db');
 $query = $db->convertBoundParams('SELECT DISTINCT COUNT( AS ilosc from table JOIN table2 ON table.klient = :id: AND = :id:', ['id' => $id]);
  return $db->fetchAll($query['sql'], \Phalcon\Db::FETCH_OBJ, $query['params']);

It binds paramter and returns an object