Array to string conversion cakephp

前端 未结 4 1413
抹茶落季
抹茶落季 2021-01-29 14:30

I\'m working on Cake PHP. Please give me a solution to solve this:

Controller.php:

public function test() {
    $this->set(\'users_l         


        
4条回答
  •  自闭症患者
    2021-01-29 15:11

    this Worked For me. Hope it will also work for you Here is my ctp file code

     $this->Form->input('answertype',array('div'=>false,'label'=>false,'type'=>'select','multiple'> => 'checkbox', 'options' =>  $arrayOptions, 'class' => 'form-control  dropdown-menu-item '));
    

    When i Debug in controller i got Result like This

    array(
    'PackageDescription' => array(
        'name' => 'Special Di scout Package',
        'question' => '20',
        'revision' => '32',
        'experttype' => '100',
        'responsetime' => '6',
        'answertype' => array(
            (int) 0 => 'image',
            (int) 1 => 'audio'
        ),
        'support' => 'email&sms',
        'status' => 'public'
    )
    

    )

    and i make Some Changes in My Model to Store Any Array as String

     public function beforeSave($options = array()) {
            if(!empty($this->data[$this->alias]['answertype']) && $this->data[$this->alias]['answertype'] != ''){
                $subArr = $this->data[$this->alias]['answertype'];
                $this->data[$this->alias]['answertype'] = implode(',', $this->data[$this->alias]['answertype']);
                $my_model = ClassRegistry::init('Answer');
                $AnswerInfo = $my_model->find('all', array('conditions' => array('Answer.name' => $subArr), 'fields' => array('Answer.name', 'Answer.name')));
                if(!empty($AnswerInfo)){
                    $answertype = array();
                    foreach($AnswerInfo as $info){
                        $answertype[] = $info['Answer']['name'];
                    }
                    $this->data[$this->alias]['answertype'] = implode(',', $answertype);
                }
            }   
            if (!empty($this->data[$this->alias]['name']) && empty($this->data[$this->alias]['slug'])) {
                if(!isset($this->data[$this->alias]['id'])){
                    $this->data[$this->alias]['slug']=$this->stringToSlug($this->data[$this->alias]['name']);
                }else{
                    $this->data[$this->alias]['slug']=$this->stringToSlug($this->data[$this->alias]['name'],$this->data[$this->alias]['id']);
                }    
            }
            return true;
        }
    

提交回复
热议问题