dongyu7074 2012-05-13 00:23
浏览 38
已采纳

带有SQL函数的CakePHP列表

I would like generate list like day=>title:

$news = $this->News->find('list', array(
    'conditions' => array(
        'News.created LIKE' => '2008-09%'),
    'fields' => array(
        'DAY(News.created) AS day',
        'News.name'),
    'recursive' => -1));

...but doesn't work, why?

Function SUBSTR/SUBSTRING also...

When I use find with 'all' property, the function DAY works good!

  • 写回答

1条回答 默认 最新

  • duan35557593 2012-05-13 01:02
    关注

    It won't work because DAY(News.created) is a computed value, but it will probably work if you make it a virtual field.

    Note that when you use 'all', each row on the results array will have a [0][day] key for that value, instead of [News][day]. This means Cake won't recognize it as a field from model News, and that's why you can't use it with 'list'.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型