I have a problem some time ago regarding a project I'm developing in cakephp , my view can not read a select with < in> 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 fetching " username " from table A to table B, and this table B my view is able to read normally. With this select my bank brings the query exactly what I need, but my view does not show the result and returns null. Or it says if I try to make the view like this: $ post-> users-> username, returns an error that does not find the users object.