3
I have a little problem for some time regarding a project that I am developing in cakephp, mine view can’t read a select with Inner Join table.
Controller:
           public function initialize()
       {
           $posts = $this->Posts->find("all",array(
              "joins" => array(
                  array(
                    "table" => "users",
                    "alias" => "User",
                    "type" => "INNER",
                    "conditions" => array("Post.user_id = User.id "),
                    "fields" => array('Post.*', 'User.username')
                   )
               )
            )
         );
model;
      public function initialize(array $config) {
          $this->addBehavior('Timestamp');
          $this->displayField('title');
         //join     
         $this->belongsTo('User');
}
View
<?= $post->username ?>
SQL code
SELECT posts.*,
       users.username
FROM   posts
       INNER JOIN users
               ON ( posts.user_id = users.id ) 
Explaining better, this query is seeking the "username" from table A to table B, and this table B of mine view can do the reading normally. With this select my bank brings the consultation exactly what I need, but my view does not display the result and returns null. Or it says if I try to do the view like this: $post->users->username, returns an error that does not find the object users.
How you are passing the data to the view?
– Sr. André Baill
<?= $post->username ? > is my view
– Lucas L