I m trying to pass comma separated values inside IN condition in cakephp 3 but it gets values with single quotes inside brackets ('12,18').
Please suggest me how to remove this.
Expected output (12,18)
Below is my code
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;
}
}
}
}
My Array data
$acoId[] =
Array
(
[0] => 12
[1] => 18
)
I am getting output like
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')
In Cakephp you can directly pass array for IN clause instead imploding it with comma. Use $acoId array in your query:
$arac = $acosName->find()->where(['id IN' => $acoId]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.