如何在IN条件cakephp中删除单引号

时间:2018-06-28 12:00:32

标签: php cakephp cakephp-3.0

我试图在cakephp 3的IN条件中传递逗号分隔的值,但它在方括号('12,18')中获得带有单引号的值。

请建议我如何删除它。

预期产量(12,18)

下面是我的代码

public function checkPermission(){
        $userId = $this->request->getSession()->read('Auth.User.id');
        $arodta = TableRegistry::get('Aros');
        $Arosdata = $arodta->find()->where(['foreign_key' => $userId])->first()->toArray();
        if(!empty($Arosdata)){
            $aroId = $Arosdata['parent_id'];
            $aroAcodata = TableRegistry::get('ArosAcos');
            $arocodata = $aroAcodata->find()->where(['aro_id =' => $aroId]);   
            if(!empty($arocodata)) {
                foreach ($arocodata as $data){ 
                    $acoId[] = $data['aco_id'];
                }
                if(!empty($acoId)){
                    $acoData = implode(',',$acoId);
                    $acosName = TableRegistry::get('Acos');
                    $arac = $acosName->find()->where(['id IN' => $acoData]);
                    sql($arac);exit;                                           
                }
            }
        }                         
    }

我的阵列数据

$acoId[] = 

    Array
    (
        [0] => 12
        [1] => 18
    )

我得到的输出是

SELECT 
  Acos.id AS `Acos__id`, 
  Acos.parent_id AS `Acos__parent_id`, 
  Acos.model AS `Acos__model`, 
  Acos.foreign_key AS `Acos__foreign_key`, 
  Acos.alias AS `Acos__alias`, 
  Acos.lft AS `Acos__lft`, 
  Acos.rght AS `Acos__rght` 
FROM 
  acos Acos 
WHERE 
  id in ('12,18')

1 个答案:

答案 0 :(得分:3)

在Cakephp中,您可以直接为IN子句传递数组,而不是用逗号将其内含。在查询中使用$ acoId数组:

$arac = $acosName->find()->where(['id IN' => $acoId]);