如何在cakephp中爆炸查找查询的值

时间:2016-06-01 09:43:47

标签: php cakephp

我得到这样的输出..

Array
(
    [User] => Array
    (
        [location_id] => 4,3
    )
)

我需要爆炸location_id的值并传入以下查找条件....但我得到错误explode()期望参数2是字符串,给定数组

public function getUserLocations() {  
    $this->loadModel('User');  
    $user_id = $this->Session->read('LoginUser.id');
    $locationid = $this->User->find('first', array(
        'conditions' => array(
            'User.id' => $user_id,
            'User.is_deleted' => 0,
            'User.status' => 1
        ),
        'fields' => array(
            'location_id'
        )
    ));
    $data = explode(",", $locationid);
    print_r($data);
    exit();
    $this->loadModel('Location');  
    $getlocations = $this->Location->find('list', array(
        'conditions' => array(
            'Location.id' => $data,
            'Location.is_deleted' => 0,
            'Location.status' => 1
        ),
        'fields' => array(
            'Location.id',
            'Location.location_name'
        ),
        'order' => 'location_name ASC'
    ));            
    $this->set('getlocations', $getlocations);
}

2 个答案:

答案 0 :(得分:2)

试试这个

$new_exploded_arr = explode(",", $your_output_arr['User']['location_id']);

答案 1 :(得分:0)

$ explosion_arr = explode(',',$ expected_arr ['User'] ['location_id']);