doutang2017 2014-03-10 09:32
浏览 34

在CakePHP中转义字段数组

I currently have:

$subQuery = $dbo->buildStatement(
        array(
            'fields' => array(
                "CASE
                    WHEN
                        Application.program_type_id = 3
                        AND Application.program_type_id IS NOT NULL
                        THEN {$keys['program_type_id_program_type_id']}
                        ELSE 0
                END as program_type_score,
                CASE
                    WHEN
                        Application.priority_subject_area_id = 1
                        AND Application.priority_subject_area_id IS NOT NULL
                        THEN {$keys['priority_subject_area_id_priority_subject_area_id']}
                        ELSE 0
                END as priority_subject_area_priority_subject_area_score,
                User.*"
            ),
            'table' => $dbo->fullTableName($this),
            'alias' => 'User',
            'limit' => null,
            'offset' => null,
            'joins' => $joins,
            'conditions' => array(
                'Application.state' => 'accepted',
                'Role.role' => 'mentor'
            ),
            'order' => null,
            'group' => null
        ),
        $this->User
    );

I need to change the case statements from this:

CASE
                        WHEN
                            Application.program_type_id = 3
                            AND Application.program_type_id IS NOT NULL
                            THEN {$keys['program_type_id_program_type_id']}
                            ELSE 0
                    END as program_type_score

to this:

CASE
                        WHEN
                            Application.program_type_id = $user['User']['value']
                            AND Application.program_type_id IS NOT NULL
                            THEN {$keys['program_type_id_program_type_id']}
                            ELSE 0
                    END as program_type_score

How do I escape $user['User']['value']? Would Sanitize::escape() work, however, it is already deprecated.

  • 写回答

2条回答 默认 最新

  • douyuepi6485 2014-03-10 10:21
    关注

    I use the single quotes in php so the way I would do this would be:

    'CASE
                        WHEN
                            Application.program_type_id = '.$user['User']['value'].'
                            AND Application.program_type_id IS NOT NULL
                            THEN {$keys['program_type_id_program_type_id']'}
                            ELSE 0
                    END as program_type_score'
    enter code here
    

    and you should be done.

    One of the reasons I prefer the single quotes. sometimes a itsybitsy more work, but usualy no worry about escaping things. Atleast als long you don't mix HTML with Javascript using PHP variables. Then it gets always messy.

    Hope that helps.

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP