简体   繁体   English

返回 cakePHP model 查找中的选定字段

[英]Return selected fields within a cakePHP model find

I simply want to return all rows from a users table but selected fields, and possible concat 2 fields.我只是想返回用户表中的所有行,但选择的字段,以及可能的 concat 2 字段。

normal sql could have just been:正常的 sql 可能只是:

SELECT id, CONCAT(`first_name`,`last_name`) AS `fullname` FROM `users`

But trying to achieve this in cake is a nightmare:但试图在蛋糕中实现这一目标是一场噩梦:

$users = $this->User->find("all") = returns everything
$users = $this->User->find("list",array("fields" => " ...) does not work either.

Can anyone please help me on how to use the cake model to achieve the simple query and return results谁能帮我看看怎么用蛋糕model实现简单的查询和返回结果

You are close:你很接近:

$this->User->find('all', array('fields' => array('CONCAT(first_name,last_name) AS fullname', 'otherfield'), 'contain' => array());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM